python:socket传输大文件
大家讲道理
大家讲道理 2017-04-18 09:29:59
0
1
479
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
刘奇

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))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template