//
//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");
}
}
本文介绍了一个使用C++实现的简单请求-回复服务示例。该服务通过ZMQ库建立REP套接字,并连接到本地主机的5560端口。服务端接收客户端发来的Hello消息并回复World。
1608

被折叠的 条评论
为什么被折叠?



