[zeromq-dev] How to send binary and text massage in one massage
Joshua Foster
jhawk28 at gmail.com
Thu Jan 10 23:34:51 CET 2013
It is much cleaner and faster to just send a multipart message using
zeromq. The multipart is still considered a single ZMQ message and will
be delivered atomically. The guide has some more examples.
Joshua
It would look something like this:
import org.zeromq.ZMQ;
String xml = "<somexml/>"
byte[] attachment = new byte[]{1, 2, 3, 4};
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket push = context.socket(ZMQ.PUSH);
push.connect("tcp://127.0.0.1:1234");
ZMQ.Socket pull = context.socket(ZMQ.PULL);
pull.bind("tcp://*:1234");
push.send(xml.getBytes(), ZMQ.SND_MORE);
push.send(attachment, 0);
String rxml = new String(pull.recv(0));
byte[] rattachment = pull.recv(0);
> Meir Yanovich <mailto:meiryanovich at gmail.com>
> January 10, 2013 6:06 AM
> so if i understand it right ,
> ( in Java ) i need instead of sending XML marshaled as my main
> massaging structure ( using Jaxb)
> i will created new java class that has 2 members 1 for the xml and
> the second as the file as base64 encoded.
> then i will just send this class on the wire ?
> and in the client i will just decode the class and handle the 2
> members of the class ?
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> Wes Young <mailto:wes at barely3am.com>
> January 10, 2013 5:46 AM
> seems like you could just [compress and/or] base64 encode the entire
> thing before it hits the zmq stack and de-combobulate it on the other
> end, then the multi-messaging should be easier(?). that way you're
> just handing a string to the zmq stack and leaving the heavy lifting
> to your application.
>
>
> --
> Wes
> wesyoung.me
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> Matias Guijarro <mailto:matias.guijarro at esrf.fr>
> January 10, 2013 3:23 AM
> Hi,
>
> Maybe the easiest is to keep the xml format for messages,
> and to encode the binary file into base64 for example.
>
> Or you can maybe use multi-part messages of zmq, first part
> being xml and second (optional ?) part a binary chunk
> corresponding to your file.
>
> Cheers,
> Matias.
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> Meir Yanovich <mailto:meiryanovich at gmail.com>
> January 10, 2013 3:16 AM
> Hello all
> im new to zeromq, i setup basic multithreaded server and simple client
> that are working great ,
> but the communication between them is xml ( using Jaxb marshaling ) .
> now i want to keep the xml massaging and to add sending binary file on
> the wire from the server to client .
> what is the best approach to do it ?
> Thanks
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130110/1e0b8d6c/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compose-unknown-contact.jpg
Type: image/jpeg
Size: 770 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130110/1e0b8d6c/attachment.jpg>
More information about the zeromq-dev
mailing list