Added a check to make sure a valid socket has been set.