[zeromq-dev] Router-Dealer Example not working in C on 4.0.4 ZMQ release

Goswin von Brederlow goswin-v-b at web.de
Tue Jul 29 13:31:02 CEST 2014


On Wed, Jul 23, 2014 at 12:50:37PM -0700, Badhrinath Manoharan wrote:
> Hi Peter,
> 
> Thanks  a lot for your response. I was able to try the same as what you had
> mentioned. I used the raw Zeromq APIs instead of the C binds. Below is my
> code and the result that I get when. I still don't see them working. Please
> let me know where I am going wrong here.
> 
> #include </usr/local/include/zmq.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <string.h>
> #include <assert.h>
> 
> int main (void)
> {
>     char buffer[15];
>     void *context = zmq_ctx_new ();
>     void *router = zmq_socket (context, ZMQ_ROUTER);
>     void *dealer = zmq_socket (context, ZMQ_DEALER);
> 
>     memset(buffer, 0, 15);
>     zmq_bind(router, "tcp://127.0.0.1:9990");
>     zmq_connect(dealer, "tcp://127.0.0.1:9990");
> 
>     printf("Sending Message from Dealer\n");
>     zmq_send(dealer, "Hello World", 11, 0);
>     printf("Waiting to receive message from Dealer\n");
>     zmq_recv(router, buffer, 15, 0);
>     printf("Received message from Dealer: %s\n", buffer);
> 
>     zmq_close(dealer);
>     zmq_close(router);
>     zmq_ctx_destroy(context);
>     return 0;
> }
> 
> bash-3.2$ ./zmq_router_dealer
> Sending Message from Dealer
> Waiting to receive message from Dealer
> Received message from Dealer:
> bash-3.2$
> 
> Thanks
> Badhri

A side note that I feel is extremly important when something doesn't work:

CHECK RETURN VALUES

How do you know zmq_bind() worked? zmq_connect()? zmq_send()? Any of
them can fail and then your zmq_recv() will wait forever.

MfG
	Goswin



More information about the zeromq-dev mailing list