Change from end to write for the socket

-socket.end('\n')
+socket.write('\n')