Skip to content

Instantly share code, notes, and snippets.

@AshuJoshi
Created July 24, 2015 23:07
Show Gist options
  • Select an option

  • Save AshuJoshi/9699922356744b4ef2fa to your computer and use it in GitHub Desktop.

Select an option

Save AshuJoshi/9699922356744b4ef2fa to your computer and use it in GitHub Desktop.

Revisions

  1. AshuJoshi created this gist Jul 24, 2015.
    30 changes: 30 additions & 0 deletions tcpSocketServer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    /*
    Simple Node.js TCP Socket Server
    Author: Ashu Joshi
    */

    "use strict'";
    const SERVER_PORT = 10000;
    const
    net = require('net'),
    server = net.createServer(function (connection) {
    console.log('Client Connected');

    connection.on('end', function () {
    console.log('Client Disconnected');
    });

    connection.on('data', function(data){
    console.log('Receiving data from client....');
    var response = data.toString().trim();
    // Log the data received
    console.log(response);
    });
    });

    // listen on the port, '' implies all interfaces, function called when server binds to the port
    server.listen(SERVER_PORT, '', function () {

    console.log('Server Bound');

    });