Skip to content

Instantly share code, notes, and snippets.

@8wgf3b
Created February 5, 2021 09:03
Show Gist options
  • Save 8wgf3b/2d0e998503fa9e53a2507d172888f144 to your computer and use it in GitHub Desktop.
Save 8wgf3b/2d0e998503fa9e53a2507d172888f144 to your computer and use it in GitHub Desktop.
import websockets
import json
import asyncio
uri = "ws://localhost:5511"
async def subscribe(*args):
async with websockets.connect(uri) as websocket:
# subcription
submsg = f"sub . (`gendata; `{'`'.join(args)})"
await websocket.send(submsg)
# updates
while True:
json_string = await websocket.recv()
data = json.loads(json_string)
print(data)
asyncio.get_event_loop().run_until_complete(subscribe("A", "B"))
# asyncio.run(subscribe("A", "B"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment