In [3]: sock.sendto(b'01234567', receiver) Out[3]: 8
In [4]: sock.sendto(b'01234567', receiver) Out[4]: 8
In [5]: sock.sendto(b'01234567', receiver) Out[5]: 8
In [6]: sock.sendto(b'01234567', receiver) Out[6]: 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
In [1]: sock.bind(('localhost', 10002))
In [2]: receiver = ('localhost', 10001)
In [3]: print(sock.recvfrom(1024)) (b'01234567', ('127.0.0.1', 10001))
In [4]: print(sock.recvfrom(4)) (b'0123', ('127.0.0.1', 10001))
In [5]: print(sock.recvfrom(4)) (b'0123', ('127.0.0.1', 10001))
In [6]: print(sock.recvfrom(4)) (b'0123', ('127.0.0.1', 10001))
In [7]: print(sock.recvfrom(4))
We can see that if the bufsize is smaller the length of the packet received, will only read bufsize bytes of the received data, and the rest of that packet will not be returned in subsequent reads.