Fix a bug in the socket opening code