Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,28 @@
|
|
1 |
import websockets
|
|
|
2 |
|
3 |
-
def hello():
|
4 |
uri = "ws://localhost:8765"
|
5 |
-
|
6 |
# Connect to the WebSocket
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
'{"data":["spider",1683852825,8,4,true],"event_data":null,"fn_index":2,"session_hash":"kb46puzhzr"}'
|
15 |
-
]
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# Send the message
|
21 |
-
websocket.send(message)
|
22 |
-
|
23 |
-
# Receive the response
|
24 |
-
response = websocket.recv()
|
25 |
-
print(f"Received: {response}")
|
26 |
|
27 |
-
|
28 |
-
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
-
|
|
|
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 |
+
'{"data":["spider",1683852825,8,4,true],"event_data":null,"fn_index":2,"session_hash":"kb46puzhzr"}'
|
12 |
+
]
|
13 |
|
14 |
+
for message in messages:
|
15 |
+
print(f"Sending: {message}")
|
16 |
|
17 |
+
# Send the message
|
18 |
+
await websocket.send(message)
|
|
|
|
|
19 |
|
20 |
+
# Receive the response
|
21 |
+
response = await websocket.recv()
|
22 |
+
print(f"Received: {response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
async def main():
|
25 |
+
await hello()
|
26 |
|
27 |
if __name__ == "__main__":
|
28 |
+
asyncio.run(main())
|