ultimatepp/bazaar/ZMQ_HelloWorld_Clnt/ZMQ_HelloWorld_Clnt.cpp
tojocky 0e88c146af ZMQ (ZeroMQ) library and a little example: A high-performance asynchronous messaging library (inproc, IPC, TCP, and multicast realization) http://www.zeromq.org/ .
Tested on linux32 (ubuntu 10.10) and win32 (windows XP SP3).

git-svn-id: svn://ultimatepp.org/upp/trunk@3264 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2011-03-06 11:13:56 +00:00

38 lines
902 B
C++

#include <ZMQ/ZMQ.h>
#include <Core/Core.h>
using namespace Upp;
//
// Hello World client
// Connects REQ socket to tcp://localhost:5555
// Sends "Hello" to server, expects "World" back
//
//#include <string.h>
//#include <stdio.h>
//#include <unistd.h>
CONSOLE_APP_MAIN{
String connect_str("tcp://localhost:5555");
zmq::context_t context (1);
// Socket to talk to server
printf ("Connecting to hello world server...\n");
zmq::socket_t socket (context, ZMQ_REQ);
socket.connect(~connect_str);
int request_nbr;
for (request_nbr = 0; request_nbr != 10; request_nbr++) {
zmq::message_t request(6);
memcpy ((void *) request.data (), "Hello", 5);
printf ("Sending Hello %d...\n", request_nbr);
socket.send(request);
zmq::message_t reply;
socket.recv (&reply);
printf ("Received World %d\n", request_nbr);
}
}