Python Forum

Full Version: UDP Socket: How to clear the buffer and ignore oldes messages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all!
I've some problem with Sockets UDP in Python:
I've a software which receives a message in input from a socket and then do some elaborations before wait for another message from the socket. Let's suppose that in the meanwhile more messages arrive:
If I'm right, they go in a buffer (FIFO) and everytime I listen the socket, I read the oldest one, right?
Is there a way to delete the buffer and everytime read the next message? I want to ignore all the oldest messages...
Another problem is that I've like a tons of message every seconds. How can I empty the buffer if they continue to fill it?
This post explains socket use pretty well, and also has sample code for building a message-based protocol.
This is something that your software has to provide.The packets that come over TCP/IP are not guaranteed
to come in order, and duplicate packets may arrive.

Read: http://stackoverflow.com/questions/17667...nt-of-data
Try their solution
@Larz60+ noticed it. You need the buffer because one packet could arrive before another in a wrong order.
Thank you for the answers...but I'm using UDP socket and not TCP/IP.

Do you know if is it possible to tell to the socket to overwrite old messages with the new one? Can I hold in memory only 1 message and when 1 newest arrives let it overwrite the old one? 

thanks (and sorry for my english :) )