继 <ZMQ的学习和研究> Request-reply worker in C++

来源:互联网 发布:阿里云系统怎么样os 编辑:程序博客网 时间:2024/05/19 12:26

//
//Request-reply service in C++
//Connects REP socket to tcp://localhost:5560
//Expects "Hello" from client, replies with "World"
//
// Olivier Chamoux <olivier.chamoux@fr.thalesgroup.com>

#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");

        }
}

0 0
原创粉丝点击