If I'm lonely, I try to figure what I'm lonely for - what's missing that I want.
To help combat loneliness, I chat with a friend on the phone, come online here and see what's happening, read a novel, draw, listen to music, go out to do things where I have to interact (even minimally) with other people. (TBH, when I learned to enjoy my own company - alone - a lot of the loneliness disappeared. Not all of it, but a lot of it. I still have my moments.)