[zeromq-dev] How to send/receive a custom C++ object via zeromq sockets?

Riskybiz riskybizLive at live.com
Tue Sep 17 18:27:58 CEST 2013

So, I've got a working implementation of a zeromq REQ-REP socket pattern and
am using it to pass data in the form of character strings between a server
and several clients, like so:

Sample comma separated data strings sent as a multipart message (of several
thousand parts), each line is a complete instruction for the client to draw
something on screen:


414,2095, at ESU13,upper,1,1,41528.600694,41528.602778,1679.75000,1679.75000,16

415,2095, at ESU13,lower,1,1,41528.600694,41528.602778,1679.50000,1679.50000,16

416,2095, at ESU13,marker,1,1,41528.602778,41528.602778,1679.75000,1680.50000,1

417,2095, at ESU13,rectangle,1,1,41528.600694,41528.603472,1679.75000,1679.5000

418,2095, at ESU13,label,1,1,41528.600694,1679.50000,ID:2095 0.0149% 5Bars 100D


My issue is that each of the data strings has to be composed at the server
and then decoded at the client end to extract the data; this works but is
not very elegant, I'm sure there is a better and more efficient way... 


I have the notion that I'd like to try encapsulating each line of the data
to be sent in a custom class object object instance; then serialize each
object, pass it through the REQ-REP sockets and deserialise to reconstruct
the object at the client end.  The simple class would be in the format like
so; only comprising data members.


class Instruction




Instruction(const unsigned int &intData, const double &dblData, const
std::string &strData): IntData(intData), DblData(dblData), StrData(strData)




//Data Members

const unsigned int IntData;

const double DblData;

const std::string StrData;



Trouble is I don't know how to implement this practically.  Is anyone able
to provide a simple example of how to accomplish serialising and
deserialising a custom object and sending it though a REQ-REP socket pair?
Or does anyone know of a good online tutorial on this subject? I'm working
with Visual Studio 2012 Express in C++.


With very many thanks,





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130917/611b4ca0/attachment.htm>

More information about the zeromq-dev mailing list