Created
August 5, 2011 11:19
-
-
Save baversjo/1127335 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'); | |
function connect_server(cb){ | |
var conn = net.createConnection(8006,cb); | |
conn.setEncoding('utf8'); | |
return conn; | |
} | |
var conn = connect_server(function(){ | |
conn.write("msg1"); | |
conn.addListener("data",function(data){ | |
conn.write("msg2",function(){ | |
conn.write("msg3"); | |
}); | |
}); | |
}); |
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
got message: msg1 | |
got message: msg2msg3 |
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 server = net.createServer(function(socket){ | |
socket.setTimeout(0); | |
socket.setEncoding("utf8"); | |
socket.addListener("data", function(rawData){ | |
if(rawData == 'msg1'){ | |
socket.write('msg-server'); | |
} | |
console.log('got message:',rawData); | |
}); | |
}); | |
server.listen(8006); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment