c++ - Zeromq zmsg unwrap returns empty address -


im trying simple req - router example using zmsg, seems when unwrap message, address invalid.

as example: client.cpp

zmq::socket_t *client = new zmq::socket_t (context, zmq_req); int linger = 0; client->connect ("tcp://localhost:5555"); client->setsockopt (zmq_linger, &linger, sizeof (linger));  std::string identifier = "mdpc01"; std::string body = "im saying hi!"; zmsg *request = new zmsg(body.c_str()); request->push_front((char *)identifier.c_str()); request->send(*client); 

broker.cpp

zmq::context_t context(1); zmq::socket_t frontend (context, zmq_router); zmq::socket_t backend  (context, zmq_router); frontend.bind("tcp://*:5555");    //  clients backend.bind("tcp://*:5556");     //  workers  std::vector<zmq::pollitem_t> items = {{static_cast<void *> (backend), 0, zmq_pollin, 0}, {static_cast<void *> (frontend), 0, zmq_pollin, 0}};  zmq::poll (items, -1); if (items [1].revents & zmq_pollin) {     zmsg *client_msg = new zmsg(frontend);     std::string address = client_msg->unwrap();     client_msg->body_set("replying server!!");     client_msg->wrap(address.c_str(),"");     client_msg->send(frontend);     delete client_msg;    } 

thing is, if msg.dump in client before sending message, outputs this:

[006] mdpc01 [013] im saying hi! 

if same after receiving on broker, outputs this:

[005] 006b8b456b [000]  [006] mdpc01 [00d] im saying hi! 

so, has inserted @ beginning guess address. after doing unwrap , wrap again, if dump before sending message output follows:

[000]   [000]  [006] mdpc01 [016] replying server!! 

what has happened address? why wasnt inserted properly? client doesnt receive messages, , guess because router discards them not having proper address.

edit

just after unwrap:

[006] mdpc01 [00d] im saying hi! 

address after unwrap, doing

std::cout << "address -" << address << "-\n"; 

prints:

address -- 

and if add:

std::cout << "address -" << client_msg->address() << "-\n"; 

it prints:

address -mdpc01- 

just after body_set:

[006] mdpc01 [016] replying server!! 


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -