【发布时间】: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