gpt4 book ai didi

node.js - 重新连接事件时是否重用套接字?

转载 作者:太空宇宙 更新时间:2023-11-03 23:32:50 27 4
gpt4 key购买 nike

当用户连接到服务器时创建套接字。

由于 interwebz 故障,连接中断。

客户端自动重新连接。

socket连接会和他第一次连接时一样吗?或者套接字会是一个新的吗?

谢谢!

最佳答案

重新连接时会建立新连接。可以通过打印socket.id来检查。

在服务器上:

var io = require('socket.io)(server);
io.on('connection', function (socket) {
console.log('socket id is ' + socket.id); }

Excerpt from socket.io documentation

The property is present once the socket has connected, is removed when the socket disconnects and is updated if the socket reconnects.

关于node.js - 重新连接事件时是否重用套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36103281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com