Fixed NullPointerException on socket.close