message = json.dumps(command)
await websocket.send(message)
print(f"Sent: {message}")
- await asyncio.sleep(0)
async def receive_events(websocket):
async def main():
async with websockets.connect(f"ws://localhost:8080") as websocket:
+ print("Sending commands to anonymous websocket.")
command_task = asyncio.create_task(test_commands(websocket))
+ print("Receiving messages from the websocket.")
event_task = asyncio.create_task(receive_events(websocket))
+ print("Await command sending task.")
await command_task
- await asyncio.sleep(3.0)
+ print("Wait for 0.1 seconds for command messages.")
+ await asyncio.sleep(0.1)
+ print("Wait for 1.9 seconds for delayed messages.")
+ await asyncio.sleep(1.9)
async with websockets.connect(f"ws://localhost:8080/Example-Client") as websocket:
+ print("Sending commands to websocket 'Example-Client'.")
command_task = asyncio.create_task(test_commands(websocket))
+ print("Receiving messages from the websocket.")
event_task = asyncio.create_task(receive_events(websocket))
+ print("Await command sending task.")
await command_task
- await asyncio.sleep(3.0)
+ print("Wait for 0.1 seconds for command messages.")
+ await asyncio.sleep(0.1)
+ print("Wait for 1.9 seconds for delayed messages.")
+ await asyncio.sleep(1.9)
if __name__ == '__main__':
asyncio.run(main())