tcp传输
node.js tcp服务端
var net = require("net"); var host = '127.0.0.1'; var port = '9999'; var Event = require("./Event"); net.createServer(function(sock){ console.log("connected:"+sock.remoteAddress+":"+sock.remotePort); sock.on('data', function(data){ console.log("data:"+sock.remoteAddress+':'+data); sock.write("success"+"rn"); var json = JSON.parse(data); var e = new Event(); console.log(json); e.trigger(json.type, json); }); sock.on('close', function(data){ console.log("closed:"+sock.remoteAddress+':'+sock.remotePort); }); sock.on('error', function(err){ console.log(err); }) }).listen(port, host); console.log('Server listening on '+host+':'+port);