exports.createLocalServer = function (port) { PORT = port;
var server = net.createServer(function (sock) {
logger.info('CONNECTED: ' +
sock.remoteAddress + ':' + sock.remotePort);
sock.on("data", function (data) {
//do something
});
sock.on("close", function (data) {
logger.info('CLOSED: ' +
sock.remoteAddress + ' ' + sock.remotePort);
});
}).listen(PORT, HOST);
server.on("listening", function () {
logger.info("server listening:" + server.address().port);
});
server.on("error", function (exception) {
logger.error("server error:" + exception);
});
} 这是服务端代码,node版本0.8.20当客户端关闭连接后,服务端响应sock.on(“close”)事件没问题。 当我用node 0.10.14版本时候出现如下错误:events.js:72 throw error; Error: read ECONNRESET at errorExecption(net.js:901:11) at TCP.onread(net.js:556:19); 添加解决方法 sock.on("close", function (data) {
logger.info('CLOSED: ' +
sock.remoteAddress + ' ' + sock.remotePort);
});
nodejs版本发生变化,导致代码也要修改,郁闷,不知道有没有人遇到过。
3 回复