Created
July 6, 2015 08:37
-
-
Save MickaelCruzDB/1dd367f77e6e1d2e3d6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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('http://google.com'); | |
} | |
}); | |
// 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