nodejs的net模块我页面没动,为啥自己就断开连接了,自己就执行close事件了,望各位大神看看!
发布于 2年前 作者 438041502 1062 次浏览
5 回复

同问啊,我也是自动断了

可以的话 看看代码

var net = require(‘net’); var port = 12211; var host = 'openapi.exmail.qq.com’;

var client= new net.Socket(); client.setEncoding(‘binary’); var sendstr = 'ver=1385039902768&access_token=sdadas’; //连接到服务端 client.connect(port,host,function(){

console.log('here');
client.write("POST /openapi/listen HTTP/1.1\r\n"+
            "Host: openapi.exmail.qq.com\r\n"+
            "Connection: keep-alive\r\n"+
            "Content-Length:"+ sendstr.length+"\r\n"+
            "\r\n"+
            sendstr
);  

}); client.setKeepAlive(true);

client.on('timeout’, function(){

console.log('time out');    

})

client.on('data’,function(data){ console.log('recv data:’+ data);

}); client.on('error’,function(error){

console.log('error:'+error);
client.destory();

}); client.on('close’,function(){

console.log('Connection closed');

});

正常啊,你socket 发post ,qq那边又不是长连接,肯定断撒

回到顶部