Node.js/TCP:修订间差异
来自康健生活
| (未显示同一用户的3个中间版本) | |||
| 第9行: | 第9行: | ||
# 客户端自定义心跳消息头,服务器接收后进行回应。 | # 客户端自定义心跳消息头,服务器接收后进行回应。 | ||
# TCP 协议自带的保活功能。 | # TCP 协议自带的保活功能。 | ||
== 实现 == | |||
# 客户端意外断开链接的处理方式 | |||
<syntaxhighlight lang="javascript"> | |||
Insert comment here | |||
</syntaxhighlight> | |||
== 长连接 == | |||
== 心跳包 == | |||
== 断开 == | |||
断开连接监听。 | |||
TODO, thinkjs, 等待详说。 | |||
<syntaxhighlight lang="javascript"> | |||
this.ctx.req.on('error', () => { | |||
console.log('req error'); | |||
}); | |||
this.ctx.req.on('close', () => { | |||
console.log('req close'); | |||
}); | |||
this.ctx.res.on('error', () => { | |||
console.log('res error'); | |||
}); | |||
this.ctx.res.on('close', () => { | |||
console.log('res close'); | |||
}); | |||
this.ctx.socket.on('error', () => { | |||
console.log('socket error'); | |||
}); | |||
this.ctx.socket.on('close', () => { | |||
console.log('socket close'); | |||
});</syntaxhighlight> | |||