clone3 commited on
Commit
83fea52
·
1 Parent(s): 3ad6834

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -1,28 +1,27 @@
1
- import websockets
2
- import asyncio
3
 
4
- async def hello():
5
  uri = "ws://localhost:8765"
6
 
7
  # Connect to the WebSocket
8
- async with websockets.connect(uri) as websocket:
9
- messages = [
10
- '{"fn_index":2,"session_hash":"kb46puzhzr"}',
11
- ]
12
 
13
- for message in messages:
14
- print(f"Sending: {message}")
 
15
 
16
- # Send the message
17
- await websocket.send(message)
18
 
19
- # Receive the response
20
- response = await websocket.recv()
21
- print(f"Received: {response}")
22
 
23
- async def main():
24
- await hello()
 
 
 
 
25
 
26
  if __name__ == "__main__":
27
- loop = asyncio.get_event_loop()
28
- loop.run_until_complete(main())
 
1
+ import websocket
 
2
 
3
+ def hello():
4
  uri = "ws://localhost:8765"
5
 
6
  # Connect to the WebSocket
7
+ ws = websocket.create_connection(uri)
 
 
 
8
 
9
+ messages = [
10
+ '{"fn_index":2,"session_hash":"kb46puzhzr"}',
11
+ ]
12
 
13
+ for message in messages:
14
+ print(f"Sending: {message}")
15
 
16
+ # Send the message
17
+ ws.send(message)
 
18
 
19
+ # Receive the response
20
+ response = ws.recv()
21
+ print(f"Received: {response}")
22
+
23
+ # Close the connection
24
+ ws.close()
25
 
26
  if __name__ == "__main__":
27
+ hello()