Debian Codegraph @

examples/ws_echo.py

raw
1 #! /usr/bin/env python
2 """Minimal WebSocket echo client (detached mode)."""
3
4 import pycurl
5
6 c = pycurl.Curl()
7 c.setopt(c.URL, "wss://echo.websocket.events/")
8 c.setopt(c.CONNECT_ONLY, 2)
9 c.perform()
10
11 c.ws_send("hello") # str -> WS_TEXT (UTF-8 encoded)
12 data, meta = c.ws_recv(4096)
13 print("recv:", data, "flags:", meta.flags)
14
15 c.ws_close(1000, "normal closure")
16 c.close()