【问题标题】:How can I check the Websocket data is empty by using asyncio如何使用 asyncio 检查 Websocket 数据是否为空
【发布时间】:2016-12-16 17:30:56
【问题描述】:

我正在使用 python asyncio 创建一个 websocket 客户端,但是,当我尝试以下代码时,它挂断了

message = b''
while True:
    print(11111)
    chunk = await reader.read(1024)
    print(len(chunk))
    self.message += chunk
    print(self.connection['reader'].at_eof())
    if not chunk:
        break
print('eeeeeeee')

但是挂断了输出:

11111

35

错误

如何检查缓冲区是否结束?

【问题讨论】:

    标签: python websocket python-asyncio


    【解决方案1】:

    WebSockets 是比普通 TCP 套接字复杂得多的协议。 您需要使用库来处理它:aiohttpwebsocketsautobahn

    附言

    我是 aiohttp 作者,该库支持纯 HTTP 协议以及 WebSockets。

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 2015-05-07
      • 1970-01-01
      • 2011-01-14
      • 2011-01-23
      • 1970-01-01
      • 2012-11-25
      • 2012-02-28
      相关资源
      最近更新 更多