[zeromq-dev] PUB sent, but SUB can not receive.
Richard_Newton at waters.com
Richard_Newton at waters.com
Wed Aug 14 16:36:17 CEST 2013
Is this on windows?
If so the stl implementation on widows (and clangs implementation, but not gcc) uses something called the small string optimisation, any string less
than or equal to 16 characters will be stored within the string class itself so will copy over, anything more than 16 characters will be allocated on
the heap and string will keep a pointer to it, this will not be copied over.
So try a symbol with more than 16 characters and it will probably fail.
Ric.
From: liuchuanbo at gmail.com
To: "ZeroMQ development list" <zeromq-dev at lists.zeromq.org>,
Cc: zeromq-dev-bounces at lists.zeromq.org
Date: 14/08/2013 01:59 PM
Subject: Re: [zeromq-dev] PUB sent, but SUB can not receive.
Sent by: zeromq-dev-bounces at lists.zeromq.org
Hi, Ric
Right, string is std::string.
Why Symbol(also std::string) has the correct string and Time NOT?
I'm debugging now, WData.Time is ""(a empty string).
On Aug 14, 2013, at 8:54 PM, Richard_Newton at waters.com wrote:
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.
<graycol.gif>liuchuanbo---14/08/2013 01:45:26 PM---Hi, everyone My problem is as the following:
From: liuchuanbo at gmail.com
To: zeromq-dev at lists.zeromq.org,
Date: 14/08/2013 01:45 PM
Subject: [zeromq-dev] PUB sent, but SUB can not receive.
Sent by: zeromq-dev-bounces at lists.zeromq.org
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
zeromq-dev at lists.zeromq.org
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.
===========================================================
_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
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.
===========================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130814/dd575e5a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130814/dd575e5a/attachment.gif>
More information about the zeromq-dev
mailing list