简体   繁体   English

Socket.io错误处理

[英]Socket.io error handling

I am having a problem with Socket.IO. 我遇到了Socket.IO的问题。

I am trying to reconnect the socket after the socket errors but it won't reconnect. 我试图在套接字错误后重新连接套接字,但它不会重新连接。 Here is the code: 这是代码:

socket = io.connect(host, options);
socket.on('connect', this.onConnect);
socket.on('error', function() {
    //here i change options
    socket = io.connect(host, options);
});

Why it doesn't it create the new connection? 为什么不创建新连接? (The host and port are being kept constant and it works for the first connection). (主机和端口保持不变,它适用于第一个连接)。

Try adding the option { 'force new connection': true } to io.connect . 尝试将选项{ 'force new connection': true }io.connect It sounds like it isn't retrying the connection. 听起来它没有重试连接。

Socket IO won't reconnect to a host that it has already tried, unless you specify this option. 除非您指定此选项,否则套接字IO将不会重新连接到它已尝试过的主机。

Here is a snippet with the options hash specified in-line: 这是一个带有在线指定的选项哈希的片段:

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

You can learn more about the options here: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO 您可以在此处了解有关这些选项的更多信息: https//github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM