"Correct 499,968 - Lost 2,006 - Errors 0"
Looking good. That's about 4,000 lost per million, about 0.4%, one every 250 packets on average. And that was stress-testing the regime, sending packets as fast as possible, with a round-trip time of about 10ms, about 100 interactions per second.
I haven't looked into whether they are packets to the server which are being lost, or replies coming back, but it doesn't really matter which it is.
The beauty of UDP is it's a simple regime to build upon -
ClientServerOnce I have tidied up my code I will post what I am using.
Looking good. That's about 4,000 lost per million, about 0.4%, one every 250 packets on average. And that was stress-testing the regime, sending packets as fast as possible, with a round-trip time of about 10ms, about 100 interactions per second.
I haven't looked into whether they are packets to the server which are being lost, or replies coming back, but it doesn't really matter which it is.
The beauty of UDP is it's a simple regime to build upon -
Client
Code:
skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)skt.settimeout(1)sequenceNumber = 0while True: try: gc.collect() # Maximise memory message = CreateMessge(sequenceNumber) # Form message for server skt.sendto(message.encode(), (server_ip, UDP_PORT_TO_USE)) #Send reply = skt.recv(1024).decode() # Wait for acknowledge if reply == nessage: # If acknowledged sequenceNumber += 1 # Send next message except Exception as e: if e.errno != 110: # If not timed out HandleException(e) # Handle exception
Code:
skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)skt.bind(("0.0.0.0", UDP_PORT_TO_USE))while True: try: gc.collect() # Maximise memory message, client = skt.recvfrom(1024) # Get a message HandleMessage(message.decode()) # Handle the message skt.sendto(message, client) # Acknowledge the message except Exception as e: HandleException(e) # Handle exception
Statistics: Posted by hippy — Mon Mar 11, 2024 2:41 pm