【问题标题】:React native + SSL socket: Error: xhr poll errorReact native + SSL socket:错误:xhr poll 错误
【发布时间】:2017-08-28 02:11:54
【问题描述】:

我正在使用 socket.io-client 将来自 react 本机应用程序的套接字与 ssl 套接字服务器连接,并在 connect-error 事件 - [Error: xhr poll error] 处收到错误。

这是我来自 react native(客户端)的代码:

import io from 'socket.io-client';

import Config from '../../config';

var socketConfig = {
    secure: true
}

function connect() {
    this.socket = io(Config.notificationUrl, socketConfig);
    // this.socket.connect();

    this.socket.on('connect', () => console.log("Socket connected", self.socket.id));
    this.socket.on('connect_error', (err) => console.log("connect_error", err));
    this.socket.on('error', (err) => console.log("error", err));
}

我尝试将传输:['websocket', 'polling'] 添加到 socketConfig,但我还收到了其他错误 [Error: websocket error]。也尝试使用import io from 'socket.io-client/dist/socket.io',但没有什么不同。

注意:我成功连接到使用 http 协议的套接字服务器。

我正在使用 react native 0.40.0 和 socket.io-client 1.7.3。

【问题讨论】:

  • 相同。这有什么更新吗?
  • 我通过更改服务器的配置解决了这个问题 - 将 rejectUnauthorized = false 添加到套接字的配置。

标签: node.js sockets ssl react-native


【解决方案1】:

安装2.4.0 socket.io client

这个版本有engine.io 3.5.0

它解决了我的问题。

【讨论】:

    【解决方案2】:

    如果设置'rejectUnauthorized = false',则不安全。

    https://socket.io/docs/client-api/#With-a-self-signed-certificate

    // option 2. WARNING: it leaves you vulnerable to MITM attacks!
      rejectUnauthorized: false

    【讨论】:

      猜你喜欢
      • 2016-07-09
      • 2021-10-21
      • 2017-12-14
      • 2014-12-27
      • 2021-10-07
      • 2019-06-25
      • 1970-01-01
      • 2022-06-18
      • 1970-01-01
      相关资源
      最近更新 更多