While the first problem is that you did not write the last piece of data received in the output file, you have a few more problems.
The current problem can be fixed by changing the instructions ifto the following:
if (rec.endswith(b'FIN')):
writefile.write(rec[:-3])
break
You still have other problems:
FIN, , , 1, , , .
, FIN read(), rec F FI.
>
, TCP , .
- , , .
- :
def _sendFile(self, path):
sendfile = open(path, 'rb')
data = sendfile.read()
self._con.sendall(encode_length(len(data))
self._con.sendall(data)
self._con.recv(1)
def _recieveFile(self, path):
LENGTH_SIZE = 4
writefile = open(path, 'wb')
length = decode_length(self.con.read(LENGTH_SIZE)
while (length):
rec = self.con.recv(min(1024, length))
writefile.write(rec)
length -= sizeof(rec)
self.con.send(b'A')
, / .