Python simple Socket programming, pythonsocket

Source: Internet
Author: User

Python simple Socket programming, pythonsocket

Socket programming is very important. Record it: implement communication between the server and the client (the client sends system commands, such as ipconfig, and the server executes the commands, then, the command returns the result to the client and then transmits it to the client. You can set to receive up to 1024 bytes at a time. If a file is larger than 1024 bytes, store the file and print it at a time after receiving all the data ), the Code is as follows:

Server:

 

Client:

 

 

Stick package problems

When two. when the send () Statement is executed in a row, because the two statements are executed in a row, messages may be sent together for two days, resulting in a stick package. write a time in the middle of the send () statement. sleep (0.5)
Sleeping for 0.5 seconds can solve the problem of sticking packets, but if it is real-time data, it may cause information delay, which is not allowed in many cases.
Another way is to insert a. recv () Statement Between Two send requests so that the server can receive the first data sent from the client and immediately return a confirmation request to the client,
After receiving the confirmation, the client sends the message for the second time, which solves the problem of sticking the package.

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.