我有这段代码,我想获取客户端发送的全部数据。但问题在于它是逐个打印角色。
像这样receive data ?
receive data ?
receive data _
receive data Z
receive data
receive data O
receive data ?
receive data }
receive data .
receive data ?
receive data (
receive data ?
receive data ?
receive data G
receive data ?
receive data "
receive data ?
receive data ?
receive data ?
receive data ?
receive data C
receive data ?
receive data C
receive data ?
receive data ?
receive data a
var net = require('net');
var server = net.createServer(function(socket){
socket.on('data',function(data){
console.log("receive data",data.toString());
});
});
server.listen(3333,'127.0.0.1', function () {
console.log("server is up!");
});
答案 0 :(得分:2)
未经测试但请尝试此操作:
var net = require('net');
var response="";
var server = net.createServer(function(socket){
socket.on('data',function(data){
response+=data.toString();
});
socket.on('end',function(data){
console.log("received data", response );
});
});
server.listen(3333,'127.0.0.1', function () {
console.log("server is up!");
});