Question

My impression was recvfrom() gave you the next packet on the IP and port it is listening on, and if it is not listening packets get missed. We are having an issue where the problem could be packets are queued up for recvfrom(), therefore it is listening and catching all packets even when recvfrom() is not actively listening.

I could not find definitive documentation on this. Does anybody know for sure the characteristics of recvfrom() is to not queue packets when not being called?

code example:

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

mcast_g = socket.inet_aton(group)
mreq = struct.pack('4sL', mcast_g, socket.INADDR_ANY)
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

s.bind(('', port))

while True:
    data, sender = s.recvfrom(1500)
    # Do stuff
    # Are packets being queued up here?
Était-ce utile?

La solution

There is a socket receive buffer in the kernel. recv() and friends read from the buffer, or block while it's empty. If you don't read fast enough, the buffer fills, and UDP datagrams that arrive when the buffer is full are dropped. You can vary the size of the buffer with the socket option SO_RCVBUFSIZE.

Autres conseils

It does depend on the OS implementation but there is an amount of buffering present on most modern OSs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top