I have socket python file explorer and i got an problem with sending files bigger that chunk size, it don't want to get get last 2-7 bytes I don't know why and server try to still recevive this but client think it send everythink, maybe someone will now the exception:
Client:
elif command == "DOWNLOAD":
file_name = args[0]
if os.path.exists(file_name):
file_size = os.path.getsize(file_name)
connection.sendall(f"READY|{file_size}".encode() + b"<END>")
buforr = b""
with open(file_name, 'rb') as file:
while True:
chunk = file.read(4096) # Read up to 4096 bytes
if not chunk: # End of file
break
connection.sendall(chunk + b"<END_CHUNK>")
buforr += chunk
# Ensure the last chunk is sent explicitly, even if empty
connection.sendall(b"<END_CHUNK>")
# Send confirmation message separately
connection.sendall(b"SUCCESS<END>")
print("All data sent successfully.")
else:
connection.sendall("ERROR|File not found<END>".encode())
I will send server in second message due to too big message