Feeling lonely can lead to sleepless nights for middle-aged and older adults.