socket = 'what';
//I do this when person clicks connect:
if (socket == 'what')
{
socket = io.connect();
}
else if (socket == null)
{
socket = io.connect();
socket = socket.socket.reconnect();
}
//I do other stuff with webrtc and socket.
//then when person clicks disconnect, I do:
socket.disconnect();
socket = null;
我不想编写所有代码,因为代码太多,并且我试图使其尽可能简单。基本上,在我单击“断开连接”后,套接字保持断开状态。但是,如果我再次单击“连接”,套接字仍然保持断开连接,因为我通过 console.log 记录它,它显示套接字已断开 = true 且套接字已连接 = false。
为什么一直处于断开状态?如何在不刷新浏览器页面的情况下完全刷新整个套接字(只需获得一个全新的套接字)?我只是希望它在断开连接时完全断开连接,并在重新连接时完全重新连接。而且它不起作用......
最佳答案
遇到了同样的问题。有一个 secret 选项强制新连接
:
io.connect(url, { 'force new connection' : true })
对于 1.0,您还可以使用 forceNew
。
更多信息在这里:
关于javascript - 即使我尝试重新连接,socket.io 仍保持断开连接?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29659297/