Created
July 24, 2015 23:07
-
-
Save AshuJoshi/9699922356744b4ef2fa to your computer and use it in GitHub Desktop.
A Simple TCP Socket Server using Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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