Qua*_* Vo 5 sockets ssl node.js react-native
我正在使用socket.io-clientssl 套接字服务器连接来自本机应用程序的套接字,并在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));
}
Run Code Online (Sandbox Code Playgroud)
我尝试将传输:['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。
小智 0
如果你设置'rejectUnauthorized = false',这是不安全的。
https://socket.io/docs/client-api/#With-a-self-signed-certificate
Run Code Online (Sandbox Code Playgroud)// option 2. WARNING: it leaves you vulnerable to MITM attacks! rejectUnauthorized: false
| 归档时间: |
|
| 查看次数: |
1856 次 |
| 最近记录: |