我的问题很简单,当我尝试连接到http上的socket.io服务器时,它正在工作。
但是当我尝试连接到安全服务器时,它不起作用,但它在1个月前就起作用了,而不是现在,我不知道为什么...
那是我的代码:
import io from 'socket.io-client';
let socket = io("https://foo.bar:12345", {
secure: true,
transports: ['websocket'],
rejectUnauthorized: false,
query: "authid=test"
});
socket.on("connect", (args) => {
console.log("Received Event connect---> ", args);
})
socket.on("error", (args) => {
console.log("Received Event error ---> ", args);
})
socket.on("connect_error", (args) => {
console.log("Received Event connect_error ---> ", args);
})
这对重要的是,我的代码在节点上完美地工作,但是不是在本机上,并且我有此错误:
Received Event connect_error ---> Error: websocket error
at WS.Transport.onError (transport.js:64)
at WebSocket.ws.onerror (websocket.js:150)
at WebSocket.dispatchEvent (event-target.js:172)
at WebSocket.js:266
at RCTDeviceEventEmitter.emit (EventEmitter.js:179)
at MessageQueue.__callFunction (MessageQueue.js:351)
at MessageQueue.js:116
at MessageQueue.__guardSafe (MessageQueue.js:314)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:115)
at debuggerWorker.js:70
谢谢您的帮助...;)
编辑:我已经在另一台PC上用相同的代码进行了测试,而无需重新编译并且它可以正常工作。。。为什么它不能与我的PC一起工作?我已经重置了都会缓存,没有任何变化!