Python Forum
UDP Socket: How to clear the buffer and ignore oldes messages
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDP Socket: How to clear the buffer and ignore oldes messages
#1
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?
Reply
#2
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
Reply
#3
@Larz60+ noticed it. You need the buffer because one packet could arrive before another in a wrong order.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
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 :) )
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  struct.error: unpack requires a buffer of 14 bytes upasana 0 8,573 Apr-18-2018, 11:06 AM
Last Post: upasana
  How to use fcntl.ioctl() to get output buffer of socket after sendall() operation apsaxena 0 4,720 Dec-09-2016, 12:44 PM
Last Post: apsaxena

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020