Is string here a std::string? If so you cannot do this as std::string uses more memory internally,
You'll need either a struct that uses just data arrays like:
typedef struct tag_WData
{
charTime[100];
char Symbol[100];
} WData;
Or use some serialisation mechanism such as protocol buffers.
Ric.
From: [email protected]
To: [email protected],
Date: 14/08/2013 01:45 PM
Subject: [zeromq-dev] PUB sent, but SUB can not receive.
Sent by: [email protected]
Hi, everyone
My problem is as the following:
typedef struct tag_WData
{
string Time;
string Symbol;
} WData;
On the PUB side. I can get WData.Time.
void OnData(WData wd)
{
// PUB Socket send ticker message to subscriber
int msgSize = sizeof(WData);
zmq::message_t message(msgSize);
memcpy ((void *) message.data(), &wd, msgSize);
publisher.send(message);
}
However, on the SUB side, it's very wired that I can NOT get WData.Time, but
WData.Symbol is correct.
int main (int argc, char *argv[])
{
zmq::context_t context (1); // only 1 io_threads
zmq::socket_t subscriber (context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5556");
subscriber.setsockopt(ZMQ_SUBSCRIBE, NULL, 0);
WData *msg;
while(true){
zmq::message_t message(sizeof(WData));
subscriber.recv(&message);
msg = (WData *) message.data();
// it's ERROR here. error message: Bad ptr
cout << msg->Time << endl;
}
return 0;
}
Why?
Thanks!
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
===========================================================
The information in this email is confidential, and is intended solely for the
addressee(s).
Access to this email by anyone else is unauthorized and therefore prohibited.
If you are
not the intended recipient you are notified that disclosing, copying,
distributing or taking
any action in reliance on the contents of this information is strictly
prohibited and may be unlawful.
===========================================================<<inline: graycol.gif>>
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
