[zeromq-dev] Sending image file in chunks on push-pull socket

Doron Somech somdoron at gmail.com
Tue Feb 21 15:25:20 CET 2017


What is the type of the file? is it binary? (it seems binary file, because
of the png extension)

You are trying to send it as string, I'm not sure it will work well, depend
on the binding, but binding might terminate the the buffer when zero byte
is reached.
Try this quick fix, instead of buf.ToString().substring(i,j), call
buf.slice(i,j).toString('base64').

On Mon, Feb 20, 2017 at 10:56 AM, Supraja Jayakumar <
suprajasankari at gmail.com> wrote:

> Hi Kevin
>
> Thank you for replying. I did send a detailed message a few days back but
> did not get any response.
>
> The message was as follows:
>
> I am sending an image file from 0mq server to 0mq client in 1024 byte
> chunks using pull-push socket. On the client side, i append the chunk to a
> string named chunks. It is simply initilaized like var chunks='' and reset
> to empty string on every new request. On receiving a 'success' message in
> the 'res' socket in the client side, the chunks data structure is written
> to a png file.
>
> But on the client side, i see that even before any incoming data is
> appended to chunks, the size of chunks is always between 1-20 bytes. Why is
> this ?
>
> Also, the incoming message size should be only 1024 bytes. But i get
> smaller or larger incoming chunks. Why is this ?
>
> On server side, i do:
>
> size = getFilesizeInbytes(obj.file);                    // get the size of
> the file
> buf  = fs.readFileSync(obj.file);                       // get the file in
> a buffer
> var i=0;var j=i+1024;
> while (i < size){                                   // WHILE(){ the send
> loop }
> if (j < size){
> sendingBuff = buf.toString().substring(i,j);
> push.send(sendingBuff);
> console.log('Sent file part ' + i + ' to ' + (j-1));
> i = i + 1024;
> j = i + 1024;
> }
> else{
> j = size;
> sendingBuff = buf.toString().substring(i,j);
> push.send(sendingBuff);
> console.log('Sent file part ' + i + ' to ' + (j-1));
> i = size + 1;
> rp.send('success');
> }
> }
> }
>
> On client side:
>
> Client.prototype._handleMessageFromPushSocket = function(msg) {
> fs.write('img.png', chunks, 'binary', function(err){
> if(err) {
> console.log(err);
> }
> console.log('written successfully!');
> });
> };
>
> On recieving the 'success' message from server on the 'req' socket, we do:
>
> if(response_message=='success') {
> fs.writeFile('out.png', chunks, 'binary', function(err) {
> if(err) throw err;
> console.log('Image written');
> });
> }
>
> Update: Incoming msg length becomes zero towards the end of the transfer.
> It seems this maybe a known issue as noted here ? -
> http://stackoverflow.com/questions/38420559/receiving-
> 0-size-messages-while-using-zmq-and-protobuf?noredirect=1&lq=1
>
> I am using node.js 0mq bindings on windows7 with git bash.
>
> Any help will be appreciated.
>
> Thanks
> Supraja J
>
>
> On Mon, Feb 20, 2017 at 1:27 PM, Kevin Sapper <kevinsapper88 at gmail.com>
> wrote:
>
>> Hi Supraja,
>>
>> without any details I can only point you to the guide
>> http://zguide.zeromq.org/page:all#Transferring-Files
>>
>> //Kevin
>>
>>
>> On Mo, Feb 20, 2017 at 8:46 , Supraja Jayakumar <suprajasankari at gmail.com>
>> wrote:
>>
>> An image file is transferred from zmq server to zmq client through
>> push-pull socket chunk by chunk (in 1024 bytes). I do not get the last 9KB
>> of any file i send as the incoming message length on the client side zmq
>> pull socket is zero!
>>
>> Plaform: windows/0mq bindings/node.js/visual studio 2015/git bash
>>
>> Any ideas on how to resolve this will be helpful.
>>
>> Thanks
>>
>> Supraja J
>> --
>> U
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>
>
>
> --
> U
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170221/73b54b6a/attachment.htm>


More information about the zeromq-dev mailing list