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.