[zeromq-dev] DEALER/REP problem
Whit Armstrong
armstrong.whit at gmail.com
Thu Oct 13 21:55:51 CEST 2011
I'm having trouble connecting a DEALER to a REP socket.
I thought DEALER/REP was a valid socket combo. Do I need a ROUTER or
REQ somewhere in the chain to make REP happy?
my server (using REP):
int main () {
zmq::context_t context (1);
zmq::socket_t clients (context, ZMQ_REP);
clients.bind("tcp://*:5555");
while(true) {
zmq::message_t msg;
zmq::message_t holla(10);
cout << "waiting." << endl;
cout << clients.recv(&msg) << endl;
cout << "got it." << endl;
cout << clients.send(holla) << endl;
}
return 0;
}
and client (using DEALER):
int main () {
const size_t nreq(6);
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_DEALER);
cout << "Connecting to hello world server..." << endl;
socket.connect ("tcp://localhost:5555");
while (1) {
for (int request_nbr = 0; request_nbr < nreq; request_nbr++) {
zmq::message_t request (6);
memcpy (request.data(), "Hello", 5);
cout << "Sending Hello " << request_nbr << "..." << endl;
cout << socket.send (request) << endl;
zmq::message_t reply;
socket.recv (&reply);
cout << "Received World " << request_nbr << endl;
}
}
return 0;
}
when I run, I get the following:
on the client:
warmstrong at krypton:~/dvl/zguide/examples/C++$ ./hwclient
Connecting to hello world server...
Sending Hello 0...
1
and on the server:
warmstrong at krypton:~/dvl/zguide/examples/C++$ ./mtserver
waiting.
Thanks very much.
-Whit
More information about the zeromq-dev
mailing list