Python Forum
UDP Socket: How to clear the buffer and ignore oldes messages - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: UDP Socket: How to clear the buffer and ignore oldes messages (/thread-3044.html)



UDP Socket: How to clear the buffer and ignore oldes messages - Guybrush - Apr-26-2017

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?


RE: UDP Socket: How to clear the buffer and ignore oldes messages - Larz60+ - Apr-26-2017

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/17667903/python-socket-receive-large-amount-of-data
Try their solution


RE: UDP Socket: How to clear the buffer and ignore oldes messages - wavic - Apr-26-2017

@Larz60+ noticed it. You need the buffer because one packet could arrive before another in a wrong order.


RE: UDP Socket: How to clear the buffer and ignore oldes messages - Guybrush - Apr-26-2017

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 :) )