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

Supraja Jayakumar suprajasankari at gmail.com
Mon Feb 20 09:56:13 CET 2017

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);
console.log('Sent file part ' + i + ' to ' + (j-1));
i = i + 1024;
j = i + 1024;
j = size;
sendingBuff = buf.toString().substring(i,j);
console.log('Sent file part ' + i + ' to ' + (j-1));
i = size + 1;

On client side:

Client.prototype._handleMessageFromPushSocket = function(msg) {
fs.write('img.png', chunks, 'binary', function(err){
if(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 ? -

I am using node.js 0mq bindings on windows7 with git bash.

Any help will be appreciated.

Supraja J

On Mon, Feb 20, 2017 at 1:27 PM, Kevin Sapper <kevinsapper88 at gmail.com>

> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170220/21a9441a/attachment.htm>

More information about the zeromq-dev mailing list