Created
August 6, 2012 17:09
-
-
Save heapwolf/3276706 to your computer and use it in GitHub Desktop.
streams/duplex
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
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