update tryhard websockets

This commit is contained in:
edbernar
2024-07-31 16:55:50 +02:00
parent 2e31a335e3
commit 8989e71c1a
2 changed files with 17 additions and 12 deletions

View File

@ -4,7 +4,11 @@ import websockets
async def send_messages(websocket):
while True:
message = input("Enter message to send: ")
await websocket.send(message)
if (websocket.open):
await websocket.send(message)
else:
print("Connection closed")
break
print(f"Sent: {message}")
async def receive_messages(websocket):
@ -19,5 +23,4 @@ async def main():
receive_task = asyncio.create_task(receive_messages(websocket))
await asyncio.gather(send_task, receive_task)
# Démarrer le client
asyncio.run(main())