Client disconnects immediately after connection to Node js TCP server

This is my first time with node js. I am trying to get the client to connect to the server and maintain the connection without closure.

This is all hosted in an ubuntu server edition hosted in a virtualbox.

I had checked that the server is actually listening to the port 5000 using netstat -ant

Websockets is also available on my browser.

I get the following output with error

Echo server dot come
192.168.1.107
node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: EPIPE, Broken pipe
    at Socket._writeImpl (net.js:159:14)
    at Socket._writeOut (net.js:450:25)
    at Socket.write (net.js:377:17)
    at Socket.ondata (stream.js:36:26)
    at Socket.emit (events.js:81:20)
    at Socket._onReadable (net.js:678:14)
    at IOWatcher.onReadable [as callback] (net.js:177:10)

and if i call socket.end() on the server on connection event handler i get a disconnecting client. My question is how to establish a stable connection using this code, what do i have to change or i am doing wrong here? pulling my hair out - thanks in advance!

HTML CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test RS Server (built over nodejs)</title>
<link rel="stylesheet" href="style.css"></link> 
<script src="jquery.min.js" ></script>
<script src="client.js" ></script>
</head>
<body>
<label>Message</label>
<input type="text" id="message_box"></input>
<input type="button" id="submit_btn" value="Send"></input>
<div style="clear:both;"/>
<label>Output</label>
<textarea rows="10" cols="100" id="output_box"></textarea>

</body>
</html>

CLIENT JS

var message_box; 
var output_box;
var submit_btn;
var url = "wss://192.168.1.107:5000";
var socket;

function createListeners(){
    if ("WebSocket" in window)
    {
            output_box.html("Supports sockets.");
            socket= new WebSocket(url);
            socket.onopen= function() {
                socket.send("con opened");
                output_box.html("Connection opened.");
            };
            socket.onmessage= function(response) {
              //  alert('got reply '+s);
              console.log(response);
              output_box.html(response);
            };
            socket.onclose = function()
            { 
                    // websocket is closed.
                    output_box.html("Connection is closed..."); 
            };
            submit_btn.click(function(e){
                socket.send(message_box.val());
            });
    }else{
        output_box.html("doesnt support sockets");
    };
};

$(document).ready(function(){
    message_box = $("#message_box");
    output_box = $("#output_box");
    submit_btn = $("#submit_btn");
    createListeners();
});

SERVER JS CODE

var net = require('net');
var server = net.createServer(function (socket) {
  socket.write('server says this\r\n');
   socket.pipe(socket);
});
server.on('connection', function(socket) {
    socket.write("Echo server dot come\r\n"+socket.address().address);
    console.log("Echo server dot come\r\n"+socket.address().address);
    // socket.end();
    socket.pipe(socket);
});
server.listen(5000);

You are trying to use WebScoket client with simple TCP server. This is a different protocols. You need to setup WebSocket server to make it work. You can use websocket module to do that. Look at the server example code here.