我正在使用 socket.io-client
将来自 native 应用程序的套接字连接到 ssl 套接字服务器,并在 connect-error
事件中收到错误 - [错误:xhr 轮询错误]
。
这是我来自 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协议(protocol)的socket服务器。
我正在使用 react native 0.40.0 和 socket.io-client 1.7.3。
最佳答案
如果你设置 '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
关于node.js - react native + SSL 套接字 : Error: xhr poll error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43180766/