react-native websocket ERR_NAME_NOT_RESOLVED停止网络请求

时间:2017-03-03 05:04:23

标签: sockets websocket react-native sockjs

我们的反应原生应用程序偶尔会遇到连接到我们的websocket的问题(我们正在使用 sockjs )。发生这种情况时,它会阻止所有网络请求,并基本上阻止我们的应用程序运行。

当它发生时,控制台不会停止记录:

GET http://192.168.0.11.xip.io:8080/sock/194/noeli4ep/eventsource 
net::ERR_NAME_NOT_RESOLVED

这是我们的连接脚本,它在应用程序启动时运行,它也在套接字关闭时运行(这样我们就可以重新连接到套接字)。

connectToServer() {
    if (!this.flagConnect) {
      this.webSocket = new SockJS(`${config.endpoint}sock`);
      this.webSocket.onopen = this.onOpen; // Just sets this.opened to true
      this.webSocket.onmessage = this.onMesssage; // Just reads the msgs
      this.webSocket.onclose = this.onClose; // Re-calls connectToServer()
      this.webSocket.onerror = this.onError; // Console.logs the error
    }
  }

我们正在使用React-native 0.41&在app&上使用sockJS后端(nodejs)。

1 个答案:

答案 0 :(得分:0)

我发现删除xip.io解决了这个问题。

所以使用http://<ip>:><port>很好。