我通过socket.io建立连接,这给我带来了麻烦。
在我设置我的套接字$(document).ready
下的页面上:
socket = io.connect(...)
我也有:
socket.on('connect', function() {
socket.emit(...); // initial request
});
现在我没有问题。我总是收到关于"初始请求"的预期回复。在此之后我想发送另一个请求:
$("#myButton").click(function(){
socket.emit(...);
socket.emit(...);
});
在大约1/10的时间内,这将无法获得响应,实际上它甚至都不会发送请求。
查看socket.io日志给出了这个:
socket.io-client:manager writing packet ...
socket.io-parser encoding packet ...
socket.io-parser encoding packet ...
socket.io-client:manager writing packet ...
socket.io-parser encoding packet ...
socket.io-parser encoding packet ...
socket.io-client:socket flushing 2 packets in socket
唯一的例外是非工作版本没有显示flushing
行。
所以出于某种原因,socket-io似乎在某些情况下不会冲洗......
对于非工作版本,日志在几秒钟后继续(> 20)
engine.io-client:socket writing ping packet - expected ping within 60000ms
engine.io-client:socket probe transport "websocket" failed because of error: transport closed
engine.io-client:socket socket error {"type":"TransportError","description":504}
....
如果&#34;初始请求和#34;之间的时间似乎没有区别。并且以下请求是长或短(> 30s或<2s)。
在后端我使用烧瓶,nginx等
更新
因此,进一步调查表明,即使在点击myButton
之前,我也有所不同。在点击之前锁定日志会显示以下信息:
engine.io-client:polling polling
engine.io-client:polling-xhr xhr poll
engine.io-client:polling-xhr xhr open GET: https://localhost/socket.io/?EIO=3&transport=polling&t=LD_xOEY&sid=...
engine.io-client:polling-xhr xhr data null
engine.io-client:socket probe transport "websocket" opened
engine.io-client:socket probe transport "websocket" pong
engine.io-client:socket pausing current transport "polling"
engine.io-client:polling we are currently polling - waiting to pause
engine.io-client:polling polling got data ArrayBuffer
engine.io-client:socket socket receive: type "noop", data "undefined"
engine.io-client:polling pre-pause polling complete
engine.io-client:polling paused
engine.io-client:socket changing transport and sending upgrade packet
虽然失败的案例得到了这个日志:
engine.io-client:polling polling
engine.io-client:polling-xhr xhr poll
engine.io-client:polling-xhr xhr open GET: https://localhost/socket.io/?EIO=3&transport=polling&t=LD_xTeA&sid=...
engine.io-client:polling-xhr xhr data null
engine.io-client:socket probe transport "websocket" opened
engine.io-client:polling polling got data ArrayBuffer
engine.io-client:socket socket receive: type "noop", data "undefined"
engine.io-client:polling polling
engine.io-client:polling-xhr xhr poll
engine.io-client:polling-xhr xhr open GET: https://localhost/socket.io/?EIO=3&transport=polling&t=LD_xTh-&sid=c1bc5c38a1f54c0297a79d583800f506
engine.io-client:polling-xhr xhr data null
engine.io-client:socket probe transport "websocket" pong
engine.io-client:socket pausing current transport "polling"
engine.io-client:polling we are currently polling - waiting to pause
所以...不太确定这意味着什么,是不是当websocket pong被推迟时,沟通被搞砸了?但为什么乒乓球会有延迟?
更新 这是我在服务器上运行的软件(更新,没有改进)
Babel==2.2.0
blinker==1.4
eventlet==0.18.4
Flask==0.10.1
Flask-Babel==0.9
Flask-Login==0.3.2
Flask-Principal==0.4.0
Flask-SocketIO==1.0
greenlet==0.4.9
gunicorn==19.4.5
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
paho-mqtt==1.1
py==1.4.31
pytest==2.9.1
python-engineio==0.9.0
python-socketio==1.2
pytz==2016.2
selenium==2.48.0
six==1.10.0
speaklater==1.3
Werkzeug==0.11.4