php client和node.js server通过tcp/udp传输数据


tcp传输

node.js and php work together through tcp

node.js and php work together through 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);

php tcp客户端(php使用base64把图片编码成字符串传输)