gpt4 book ai didi

socket.io - 通过 xhr-polling 和 jsonp-polling 超时连接

转载 作者:行者123 更新时间:2023-12-04 13:49:01 27 4
gpt4 key购买 nike

我尝试通过 websocket 和轮询运行我的 socket.io 程序,它们都有效。但是,当尝试运行 xhr-polling 时,它会超时。这可能是什么原因造成的?

对于这个程序,我使用的是 socket.io 1.2.1。

var options = {"force new connection":true,
"reconnect":false,
"connect timeout":10000,
"flash policy port":843,
"auto connect":true,
"path":"/sample/socket.io",
"transports":["xhr-polling"]}

this.namespace = io.connect( 'http://localhost:8190/', options);

到目前为止,我的研究对这个问题一无所知。

编辑:

这是浏览器上的一段日志。

socket.io-client:url parse http://localhost:8190/ +0ms
socket.io.js:1284 socket.io-client ignoring socket cache for http://localhost:8190/ +0ms
socket.io.js:1284 socket.io-client:manager readyState closed +0ms
socket.io.js:1284 socket.io-client:manager opening http://localhost:8190/ +0ms
socket.io.js:3524 engine.io-client:socket creating transport "xhr-polling" +0ms
socket.io.js:1284 socket.io-client:manager connect attempt will timeout after 20000 +4ms
socket.io.js:1284 socket.io-client:manager readyState opening +1ms
socket.io.js:1284 socket.io-client:manager connect_error +3ms
socket.io.js:1284 socket.io-client:manager will wait 1000ms before reconnect attempt +2ms
socket.io.js:1284 socket.io-client:manager attempting reconnect +1s
socket.io.js:1284 socket.io-client:manager readyState closed +0ms
socket.io.js:1284 socket.io-client:manager opening http://localhost:8190/ +1ms
socket.io.js:1284 socket.io-client:manager connect attempt will timeout after 20000 +0ms

这段日志不断重复,同时稳步增加超时。

最佳答案

我发现这是因为 Socket.IO 版本 1.0+ 实际上不允许设置 [websocket 和轮询] 之外的传输。将轮询设置为您的传输默认为 polling-xhr,除非您在选项中将属性 forceJSONP 和/或 jsonp 设置为 true

换句话说,代码应该是:

var options = {"force new connection":true,
"reconnect":false,
"connect timeout":10000,
"flash policy port":843,
"auto connect":true,
"path":"/sample/socket.io",
"transports":["polling"]}

this.namespace = io.connect( 'http://localhost:8190/', options);

另请注意,'auto connect' 现在是 autoConnect'force new connection' 现在是 forceNew , 'connect timeout' 现在是 timeout'reconnect' 现在是 'reconnection'

var options = {forceNew :true,
reconnection :false,
timeout":10000,
"flash policy port":843,
autoConnect:true,
"path":"/sample/socket.io",
"transports":["polling"]}

关于socket.io - 通过 xhr-polling 和 jsonp-polling 超时连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27959250/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com