Online games changed my life when I was deep in/under the valley of startup desperation. I met people I could talk about non-work things. Or whom I could joke with about my job. That also helped, trying to see the funny side of the harsh life of a company founder from the outside.
That was four years ago. Company is doing better than ever these days, not particularly thanks to me. And I don't feel too lonely these days.
Another thing that worked for a friend of mine: writing fiction. He says his characters live in his mind, like he is the hardware running the world of his books, so he never feels alone. And he also gets to interact a lot with fellow writers in the real world. Fiction writers are a very different bunch than software developers, it seems, they are more concerned about people feelings and such.