title: zmq - when to use zmq_bind or zmq_connect
body: <p>Refer to <a href="http://hintjens.wdfiles.com/local--files/main:files/cc1pe.pdf" rel="nofollow noreferrer">http://hintjens.wdfiles.com/local--files/main:files/cc1pe.pdf</a>
  Page 22 Chapter Divide and Conquer</p>
  <pre><code>                    Ventilator[PUSH]
          ___________________|____________________             
          |                  |                   |
  [PULL]Worker[PUSH] [PULL]Worker[PUSH]  [PULL]Worker[PUSH]
          |__________________|___________________|             
                             |                   
                       [PULL]Sink
                       
  // taskvent.c
      //  Socket to send messages on
      void *context = zmq_ctx_new ();
      void *sender = zmq_socket (context, ZMQ_PUSH);
      zmq_bind (sender, &quot;tcp://*:5557&quot;);
  
      //  Socket to send start of batch message on
      void *sink = zmq_socket (context, ZMQ_PUSH);
      zmq_connect (sink, &quot;tcp://localhost:5558&quot;);
                       
  // taskwork.c
      //  Socket to receive messages on
      void *context = zmq_ctx_new ();
      void *receiver = zmq_socket (context, ZMQ_PULL);
      zmq_connect (receiver, &quot;tcp://localhost:5557&quot;);
  
      //  Socket to send messages to
      void *sender = zmq_socket (context, ZMQ_PUSH);
      zmq_connect (sender, &quot;tcp://localhost:5558&quot;);
  
  // tasksink.c
      //  Prepare our context and socket
      void *context = zmq_ctx_new ();
      void *receiver = zmq_socket (context, ZMQ_PULL);
      zmq_bind (receiver, &quot;tcp://*:5558&quot;);
      
  </code></pre>
  <p>I feel confused when to use zmq_bind or zmq_connect.
  It says that most of time &quot;Server&quot; uses zmq_bind and &quot;Client&quot; uses zmq_connect.</p>
  <p>Question&gt; When I should use zmq_bind and when I should I use zmq_connect?</p>
  <p><a href="http://api.zeromq.org/" rel="nofollow noreferrer">http://api.zeromq.org/</a></p>
  <pre><code>zmq_bind - accept incoming connections on a socket  
  zmq_connect - create outgoing connection from socket
  </code></pre>