怪我咯2017-04-18 09:31:59
I’m not sure exactly where the problem lies, but I have a suggestion:
The client should not send the file size after the connection is successfully established, but send data with a fixed length. Each group of data first sends a flag length, and then sends fixed-length data. The length of the last piece of data can be easily obtained. Last sent flag 0;
The server first accepts the flag length, and then receives the data of the corresponding length. When the length is 0, the file transfer ends;
The length of the length flag is set to 4 (enough for an int of 1024)
length = int(s.recv(4).decode('utf8'))。
f.write(s.recv(length))