Service side:
1 fromSocketImport*2 3Server =socket (af_inet, SOCK_DGRAM)4Server.bind (('127.0.0.1', 8080))5 6Res1 = Server.recvfrom (1024)7 Print('First time:', Res1)8 9Res2 = Server.recvfrom (1024)Ten Print('First time:', Res2) One AServer.close ()
Client:
1 fromSocketImport*2 3Client =socket (af_inet, SOCK_DGRAM)4 5Client.sendto (b'Hello', ('127.0.0.1', 8080))6Client.sendto (b' World', ('127.0.0.1', 8080))7 8Client.close ()
Run the server first, run the client, and there is no sticky packet phenomenon,
The server run results are:
1 First time: (b'hello', ('127.0.0.1', 61924))
Because of the Windows system reason, the second time did not print out,
Change the number of bytes for the first recv of the server to 1, only receive 1 bytes h, the rest is lost,
The second received a problem for the world,windows system test:
1 Traceback (most recent): 2 " C:/users/xudachen/pycharmprojects/python Full Stack development/third module/network programming/UDP-based protocol no sticky packets/service side will occur. PY " in <module>3 res1 = server.recvfrom (1)4 oserror: [Winerror 10040] A message sent on a datagram socket is larger than the internal message buffer or some other network limit, or the buffer used by the user to receive datagrams is smaller than the datagram.
This problem does not occur with Linux systems,
python--Network Programming-----UDP protocol-based sockets do not occur sticky packets