【问题标题】:socket.io remains disconnected, even after I try to reconnect it? Why?socket.io 仍然断开连接,即使我尝试重新连接它?为什么?
【发布时间】:2015-06-21 22:47:03
【问题描述】:
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 并且套接字连接 = 假。

为什么它仍然断开连接?如何在不刷新浏览器页面的情况下完全刷新整个套接字(只需获得一个全新的套接字)?我只希望它在断开连接时完全断开连接,并在重新连接时完全重新连接。而且它不起作用....

【问题讨论】:

    标签: javascript node.js sockets socket.io client


    【解决方案1】:

    遇到了同样的问题。有一个秘密选项force new connection

    io.connect(url, { 'force new connection' : true })
    

    您也可以将forceNew 用于 1.0。

    更多信息在这里:

    https://github.com/Automattic/socket.io-client/issues/607

    【讨论】:

      猜你喜欢
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 2021-04-12
      • 1970-01-01
      • 2021-05-31
      相关资源
      最近更新 更多