WebsoketSend / app.py
clone3's picture
Update app.py
fa03655
raw
history blame
No virus
2.61 kB
import asyncio
import websockets
async def send_wss_request():
uri = "wss://clone3-imagex-clone-advance.hf.space/queue/join"
uri2 = "wss://clone3-imagex-clone-advance.hf.space/queue/join"
while True:
try:
async with websockets.connect(uri) as websocket:
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Send a message
message = '{"fn_index":2,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
message='{"data":["spiderman",1683852825,8,4,true],"event_data":null,"fn_index":2,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
async with websockets.connect(uri2) as websocket:
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Send a message
message = '{"fn_index":2,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
message='{"data":["spiderman",1683852825,8,4,true],"event_data":null,"fn_index":2,"session_hash":"kb46puzhzr"}'
await websocket.send(message)
print(f"Sent: {message}")
# Receive the response
response = await websocket.recv()
print(f"Received: {response}")
except websockets.exceptions.ConnectionClosed:
print("Connection closed. Reconnecting in 30 minutes.")
# Sleep for 30 minutes before the next iteration
await asyncio.sleep(30 * 60)
# Run the event loop
asyncio.get_event_loop().run_until_complete(send_wss_request())