Fixed socket.close exception, closes #859

The call to socket.socket.close(self) raised an exception in at least some conditions.