Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created July 5, 2015 18:24
Show Gist options
  • Save MickaelCruzDB/f9fecc415a4acf6c4fed to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/f9fecc415a4acf6c4fed to your computer and use it in GitHub Desktop.
var net = require('net');
var open = require('open');
var HOST = '127.0.0.1';
var PORT = 2401;
net.createServer(function(sock) {
// We have a connection - a socket object is assigned to the connection automatically
console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);
// Add a 'data' event handler to this instance of socket
sock.on('data', function(data) {
console.log('DATA ' + sock.remoteAddress + ': ' + data);
// Write the data back to the socket, the client will receive it as data from the server
sock.write('You said "' + data + '"');
if (data == "salut")
{
open('https://github.com/', "nwjs");
}
});
// Add a 'close' event handler to this instance of socket
sock.on('close', function(data) {
console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
});
}).listen(PORT, HOST);
console.log('Server listening on ' + HOST +':'+ PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment