I'll share what I have learned about loneliness over the years:
Human beings have certain needs; food, drink, sleep etc. and we have a solution to all of them, when you're hungry you eat, when you're thirsty you sleep, etc. Humans also have a need for companionship, but unfortunately we can't tend to that need by ourselves, we need other people to fulfill that need. Because we need companionship, but people aren't always around who are willing to give it to us, it's like being hungry but unable to feed yourself. It takes a toll on you in many ways. You have so much time lost in your own thoughts that the negative thoughts get louder and louder. You wonder why people aren't giving you companionship, first you look for flaws in other people, but because they're not around, you can't find them. So eventually you start looking for flaws with yourself, that's when it gets nasty. When you're lonely and depressed, it's natural to be extremely critical of yourself. You become convinced that everything is your fault and that you're a horrible person because you cannot fulfill this need.
To a degree, you can learn to be happy in your own company. The best way to do it is to make it so that your alone time isn't imposed on you, it's on your terms. So where do you find people to socialize with? It's not easy to face people in person when your confidence is so shattered. I found that free dating sites like OKCupid or PlentyOfFish are actually really useful. You can register as a person seeking new friends and it will match you with people with similar interests. Just message everyone it matches you with and chat with the ones who reply. Ask them questions about themselves, talk to them about your day, maybe even meet up with some if you find some good ones! You don't have to be looking for a relationship, they're geared to help you find new friends too. A tip: put your sexuality as bisexual, that way it will match you with both genders, makes it easier to make new friends of both genders. I've made a few friends that way, and it really is a nice, easy way to find people even if it's just for a bit of banter.
Try it and let us know if it helps :)
James x