Created
July 26, 2011 10:04
-
-
Save eerne/1106419 to your computer and use it in GitHub Desktop.
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'); | |
// http://nodejs.org/docs/v0.5.2/api/net.html | |
var server = net.createServer(function(socket){ | |
socket.end('goodbye\n'); | |
}); | |
// http://nodejs.org/docs/v0.5.2/api/streams.html#readable_Stream | |
server.listen(4542, 'localhost', function(){ | |
var address = server.address(); | |
//console.log('opened server on %j', address); | |
}); | |
server.on('connection', function(socket){ | |
console.log('connection'); | |
/*var pdsocket = new net.Socket(); | |
pdsocket.connect('4541', 'localhost', function(){ | |
console.log('pdsocket'); | |
});*/ | |
var pdsocket = net.createConnection(4541, 'localhost'); | |
pdsocket.on('connect', function(){ | |
//console.log('pdsocket connect'); | |
pdsocket.write('lalallaal lalalal;\n'); // FUDI stuff always ends with `;\n` | |
}); | |
socket.setEncoding('ascii'); // 'utf8', 'base64' | |
socket.on('connect', function(){ | |
console.log('connect'); | |
}); | |
socket.on('data', function(buffer){ | |
console.log('data', buffer); | |
}); | |
socket.on('close', function(){ | |
console.log('close'); | |
}); | |
}); | |
server.on('error', function(e){ | |
console.log('error'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment