Skip to content

Instantly share code, notes, and snippets.

@heapwolf heapwolf/31.js
Created Aug 7, 2012

Embed
What would you like to do?
tcp/client-server
var net = require('net');
var sock;
var port = 8089;
if(process.argv[2] === 'client') {
sock = new net.Socket();
sock.meta = 'foobar';
sock.on('data', function(data) {
console.log(String(data));
});
sock.connect(port);
sock.write('ping');
}
if(process.argv[2] === 'server') {
sock = new net.Server();
sock.listen(port);
sock.on('connection', function(socket) {
socket.on('data', function(data) {
console.log(String(data));
socket.write('pong');
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.