Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python websocket客户端连接状态-如何更新以获得正确的状态?_Python_Node.js_Websocket - Fatal编程技术网

python websocket客户端连接状态-如何更新以获得正确的状态?

python websocket客户端连接状态-如何更新以获得正确的状态?,python,node.js,websocket,Python,Node.js,Websocket,我可以使用连接到node.js服务器。当我询问pythonwebsocket客户端是否连接到服务器时,这是不准确的 发生的情况如下: Python 2.7.6 (default, Sep 9 2014, 15:04:36) >>> import websocket >>> ws = websocket.WebSocket() >>> ws.connect("ws://localhost:8081") # my websocket serve

我可以使用连接到node.js服务器。当我询问pythonwebsocket客户端是否连接到服务器时,这是不准确的

发生的情况如下:

Python 2.7.6 (default, Sep  9 2014, 15:04:36)
>>> import websocket
>>> ws = websocket.WebSocket()
>>> ws.connect("ws://localhost:8081") # my websocket server is running, so all good here.
>>> ws.connected
True      # This is correct. Now I kill the websocker server
>>> ws.connected
True      # this should be false since the server is dead.
js模块附带了
wscat
,您可以通过命令
wscat-l8081
运行websocket服务器


如何获得指示真实连接/断开连接状态的准确状态?

除非
关闭
关闭
,否则不会更新
.connected
属性。。。调用,或
recv*
接收空数据

尝试调用
recv()
,然后检查
.connected
属性