Ilya_Bykonya

Untitled

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