Files
udp_over_ws/generator.py
Danil Kolesnikov e251fcd8f1 test utils
2025-02-12 23:37:26 +03:00

29 lines
721 B
Python

import asyncio
import socket
import time
async def send_random_packets():
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
# Send a random packet to UDP port 5005
data = b'Random Data'+str(time.time()).encode()
sock.sendto(data, ('localhost', 5005))
print("Sent packet to UDP port 5005")
# Wait for a response packet from UDP port 5005
sock.recv(4096)
print("received back", data)
# Wait for 1 second before sending the next packet
await asyncio.sleep(1)
# Close the socket
sock.close()
# Run the send_random_packets coroutine in the event loop
asyncio.run(send_random_packets())