How do you define lonely? Many people think that it is only possible to be lonely because of the absence of someone. However, sometimes you can feel lonely even if you are surrounded by people. Being lonely is a personal thing, not associated with the presence of or absence of anyone. It is possible to be alone without being lonely, just as it is possible to be surrounded and feel lonely.
If being lonely is not a matter of having someone around, what is it a matter of? Often people feel lonely when relationships end, and this leads to them associating their loneliness with the lack of the person, when in reality it is due to something missing in their life. What characteristics about the relationship are leading to your feelings of loneliness now?
Loneliness and the way to rid yourself of loneliness are not caused by or solved by a person, rather it is due to your own emotional isolation. If you are the kind of person who does not really put yourself out there, chances are you will feel lonely when you don't have someone to draw you out and force you to open yourself up emotionally. If you are typically an emotionally isolated person, then those characteristics will persist despite your circumstances.
The power to not be alone/lonely is yours and yours alone. There are some people that can help you come out of your shell, and open up emotionally, but they are not the cause, you are. So, the best thing you can do if you feel lonely regularly is to analyze your feelings, and what it is that makes you isolate yourself emotionally. Is it fear of rejection? Is it a shyness that keeps you from participating? Is it lack of esteem?
Once you realize that your loneliness, heartbreak, or other trials are not caused by other people, but are controlled by yourself, you can bring them to a place where you can work on it. All too often people place the blame for their feelings on others, and thus give up the control to do anything about those feelings, or change them in any way. This is a sad mistake. When you give up your ability to control your own emotions, and take control of your own life, you give up the ability to be happy. So, while it is okay to miss people, and to feel hurt and pain at the loss of a relationship, etc. don't let that dictate to you how you will feel. You can miss someone without feeling lonely. You may have no control over getting someone back, but you can control how you choose to respond to that. If you choose to wallow in it and let loneliness isolate you, then you will be lonely. If you decide to learn from the loss, and mourn it, but still put yourself out there and have fun, then you will, and your loneliness will evaporate.