【问题标题】:python websocket client connected status - how to update so I get correct status?python websocket客户端连接状态 - 如何更新以获得正确的状态?
【发布时间】:2015-02-01 03:16:08
【问题描述】:

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

会发生什么:

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.

ws node.js 模块附带wscat,您可以通过命令wscat -l 8081 运行websocket 服务器。

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

【问题讨论】:

    标签: python node.js websocket


    【解决方案1】:

    .connected 属性不会更新,除非 closeshutdown,... 被调用,或 recv* 接收到空数据。

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

    【讨论】:

      猜你喜欢
      • 2015-05-28
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多