繼 Request-reply worker in C++

//
//Request-reply service in C++
//Connects REP socket to tcp://localhost:5560
//Expects "Hello" from client, replies with "World"
//
// Olivier Chamoux <[email protected]>

#include "zhelpers.hpp"

int main (int argc,char *argv[])
{

          zmq::context_t context(1);

          zmq::socket_t responder(context, ZMQ_REP);
          responder.connect("tcp://localhost:5560");

          while(1)
         {
       //Wait for next request from client
         std::string string= s_recv (responder);

        std::cout<< "Received request: " << string<< std::endl;

      // Do some 'work'
        sleep (1);

       //Send reply back to client
    s_send (responder, "World");

        }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章