[zeromq-dev] PUB sent, but SUB can not receive.
liuchuanbo at gmail.com
liuchuanbo at gmail.com
Wed Aug 14 17:27:27 CEST 2013
Ric,
I have tried it. You're exactly right!
OS is the Windows here.
Actually, WData.Symbol is all less than 16 characters, and WData.Time is all more than 16 characters(like 2013-08-08 10:00:00).
When I set WData.Symbol to more than 16 chars manually, pointer failed.
Please tell me how to resolve this thing?
BTW, the WData struct can not be changed.
Roy.
On Aug 14, 2013, at 10:36 PM, Richard_Newton at waters.com wrote:
> 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.
>
>
> <graycol.gif>liuchuanbo---14/08/2013 01:59:43 PM---Hi, Ric Right, string is std::string.
>
> 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.
> ===========================================================
>
> _______________________________________________
> 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/20130814/e91bec4b/attachment.htm>
More information about the zeromq-dev
mailing list