Skip to content

Instantly share code, notes, and snippets.

@AshuJoshi
Created July 24, 2015 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshuJoshi/9699922356744b4ef2fa to your computer and use it in GitHub Desktop.
Save AshuJoshi/9699922356744b4ef2fa to your computer and use it in GitHub Desktop.
A Simple TCP Socket Server using Node.js
/*
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');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment