python - 如何在 python 中使用 websockets 流式传输信息?
问题描述
我正在自学 websockets 并编写了这段代码
import asyncio
import websockets
async def stream_msgs(uri,msg):
async with websockets.connect(uri) as websocket:
await websocket.send(msg)
rec= await websocket.recv()
print(f"< {rec}")
asyncio.get_event_loop().run_until_complete( stream_msgs('wss://ws.blockchain.info/inv',"{op:unconfirmed_sub}"))
问题是它在收到消息后退出程序。当我用这个工具进行测试时,同样是流信息。如何在 python 中使用 websockets 流式传输数据?
解决方案
推荐阅读
- php - 在 Laravel - php 中使用 json_encode() 将收集和数组数据编码为 json 有什么区别?
- javascript - 使用 jQuery 2.1.0 动态添加/删除/排序输入框
- flutter - Flutter Xlider - setState - 值保持为 0 并回弹
- c# - 如何统一从数组中仅实例化一个对象
- html - 当您仅针对表格内的表格头 (TH) 时,为什么边框折叠和间距不起作用?
- flutter - 在颤振中使用字符串值而不是常量字符串
- laravel - Laravel 返回 Flash 会话
- daemon - 如何使用 Aria2c RPC 服务器作为守护进程?
- node.js - Nextjs- api 路由,如何从标头中删除 cookie?
- node.js - 如何在 MongoDB 中查找集合中的最后一个元素?