Ilya_Bykonya

Untitled

May 27th, 2024
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | Source Code | 0 0
  1. from websocket import create_connection
  2. from contextlib import contextmanager
  3.  
  4. @contextmanager
  5. def web_socket_connection(host):
  6.     ws = create_connection(host)
  7.     yield ws
  8.     ws.close()
  9.  
  10.  
  11. with web_socket_connection("ws://localhost:3071/ws/1") as ws:
  12.     ws.send("Hello, World")
  13.     print(f'Received: {ws.recv()}')
Advertisement
Add Comment
Please, Sign In to add comment