[zeromq-dev] EOF on file transfer

Tiago Hillebrandt tiagohillebrandt at ubuntu.com
Tue Dec 9 18:08:22 CET 2014


Thanks Pieter, will read it and see if can figure out what is happening.

Doron, both are PAIR.

Thanks,

2014-12-09 11:00 GMT-06:00 Doron Somech <somdoron at gmail.com>:

> What is the socket type of each?
> On Dec 9, 2014 6:47 PM, "Tiago Hillebrandt" <tiagohillebrandt at ubuntu.com>
> wrote:
>
>> Hey guys,
>>
>> I am using the below Python code to transfer big files between a server
>> and a client.
>>
>> *Implementation to send file, server*
>>
>>     CHUNK_SIZE = 250000
>>
>>     message = pair.recv() # message is the path to the file
>>
>>     filename = open(message, 'rb')
>>     filesize = os.path.getsize(message)
>>
>>     offsets = (int(ceil(filesize / CHUNK_SIZE)), 0)[filesize <= CHUNK_SIZE]
>>
>>     for offset in range(offsets + 1):
>>         filename.seek(offset)
>>
>>         chunksize = CHUNK_SIZE
>>
>>         if offset == offsets:
>>             chunksize = filesize - (CHUNK_SIZE * (offset - 1)) # calculate the size of the last chunk
>>
>>         data = filename.read(chunksize)
>>
>>         pair.send(data)
>>
>>     pair.send(b'')
>>
>> *Implementation to receive file, client*
>>
>> while True:
>>     data = pairs.recv()
>>
>>     if data is not '':
>>         target.write(data)
>>     else:
>>         break
>>
>> However, after transfer a big file using this implementation, for some
>> reason an extra data is being added at end of the file:
>>
>> *File server side*
>>
>> $ stat file.zip
>>   File: `file.zip'
>>   Size: 1503656416  Blocks: 2936840    IO Block: 4096   regular file
>>
>> *Client side*
>>
>> $ stat file.zip
>>   File: `file.zip'
>>   Size: 1503906416  Blocks: 2937328    IO Block: 4096   regular file
>>
>> The size and blocks are different between them.
>>
>> That said, do you have any suggestions to calculate/send the end of file
>> properly?
>>
>> Thanks!
>> --
>> *Tiago Hillebrandt*
>> Ubuntu Member
>> Ubuntu Brazilian Community Council Member
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>


-- 
*Tiago Hillebrandt*
Ubuntu Member
Ubuntu Brazilian Community Council Member
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20141209/fb565e28/attachment.htm>


More information about the zeromq-dev mailing list