python--Network Programming-----UDP protocol-based sockets do not occur sticky packets

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.