title: Zeromq how to make a c++ server program which allows it not to wait for client request
body: <p>I am trying Zeromq Hello world example for server and client. below is the example code</p>
  
  <pre><code>//
  //  Hello World client in C++
  //  Connects REQ socket to tcp://localhost:5555
  //  Sends "Hello" to server, expects "World" back
  //
  #include &lt;zmq.hpp&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  int main ()
  {
      //  Prepare our context and socket
      zmq::context_t context (1);
      zmq::socket_t socket (context, ZMQ_REQ);
  
      std::cout &lt;&lt; "Connecting to hello world server…" &lt;&lt; std::endl;
      socket.connect ("tcp://localhost:5555");
  
      //  Do 10 requests, waiting each time for a response
      for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
          zmq::message_t request (6);
          memcpy ((void *) request.data (), "Hello", 5);
          std::cout &lt;&lt; "Sending Hello " &lt;&lt; request_nbr &lt;&lt; "…" &lt;&lt; std::endl;
          socket.send (request);
  
          //  Get the reply.
          zmq::message_t reply;
          socket.recv (&amp;reply);
          std::cout &lt;&lt; "Received World " &lt;&lt; request_nbr &lt;&lt; std::endl;
      }
      return 0;
  } 
  </code></pre>
  
  <p>and the Server code</p>
  
  <pre><code>//
  //  Hello World server in C++
  //  Binds REP socket to tcp://*:5555
  //  Expects "Hello" from client, replies with "World"
  //
  #include &lt;zmq.hpp&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;unistd.h&gt;
  
  int main () {
      //  Prepare our context and socket
      zmq::context_t context (1);
      zmq::socket_t socket (context, ZMQ_REP);
      socket.bind ("tcp://*:5555");
  
      while (true) {
          zmq::message_t request;
  
          //  Wait for next request from client
          socket.recv (&amp;request);
          std::cout &lt;&lt; "Received Hello" &lt;&lt; std::endl;
  
          //  Do some 'work'
          sleep (1);
  
          //  Send reply back to client
          zmq::message_t reply (5);
          memcpy ((void *) reply.data (), "World", 5);
          socket.send (reply);
      }
      return 0;
  }
  </code></pre>
  
  <p>The Code works fine I am able to send the request and get the reply.</p>
  
  <p>But I want that the server should not wait for the request from the client .The server continue running and if the request from the client come it give the reply.</p>
  
  <p>What changes can I make in the program to achieve this.</p>