使用套接字
建立连接时错误:超出2000毫秒超时。对于异步测试和钩子,确保“完成( )“被调用;如果返回Promise,请确保它结算。
以下是相同
的代码参考beforeEach(function(done) {
var socketOptions = {};
var socket = io.connect("http://localhost:5000", socketOptions);
socket.on('connect', function () {
console.log('Connection Established');
setTimeout(done, 500);
});
socket.on('error', function (err) {
console.log('Connection Error', err);
setTimeout(done, 500);
});
});
在检查套接字连接的错误时,我收到了下面提到的错误:
Connection Error { Error: xhr poll error
at XHR.Transport.onError (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transport.js:64:13)
at Request.<anonymous> (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transports\polling-xhr.js:129:10)
at Request.Emitter.emit (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\node_modules\component-emitter\index.js:133:20)
at Request.onError (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transports\polling-xhr.js:307:8)
at Timeout._onTimeout (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transports\polling-xhr.js:254:18)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5) type: 'TransportError', description:400}
答案 0 :(得分:1)
通过更改socketOptions变量数据(如
)来解决问题var socketOptions = {'transports': ['websocket']};
由于错误是在传输错误轮询上,我们需要指定传输方式作为选项,如使用套接字连接选项传递