diff options
author | Tony Theodore <tonyt@logyst.com> | 2018-03-12 16:37:34 (GMT) |
---|---|---|
committer | Tony Theodore <tonyt@logyst.com> | 2018-03-12 16:37:34 (GMT) |
commit | 90fc2216c24ccb32a1933c17cd3df3b346c8d792 (patch) | |
tree | da304ed78fff9b9c54f2c4d2933d0b1a73e91458 /src/cppzmq-test.cpp | |
parent | 61587920291adde7644f91adb7c41164bc30c683 (diff) | |
download | mxe-90fc2216c24ccb32a1933c17cd3df3b346c8d792.zip mxe-90fc2216c24ccb32a1933c17cd3df3b346c8d792.tar.gz mxe-90fc2216c24ccb32a1933c17cd3df3b346c8d792.tar.bz2 |
add libzmq and cppzmq
Diffstat (limited to 'src/cppzmq-test.cpp')
-rw-r--r-- | src/cppzmq-test.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/cppzmq-test.cpp b/src/cppzmq-test.cpp new file mode 100644 index 0000000..0791808 --- /dev/null +++ b/src/cppzmq-test.cpp @@ -0,0 +1,44 @@ +/* + * This file is part of MXE. See LICENSE.md for licensing information. + */ + + +// Taken from: http://zguide.zeromq.org/cpp:hwserver +// Hello World server in C++ +// Binds REP socket to tcp://*:5555 +// Expects "Hello" from client, replies with "World" +// +#include <zmq.hpp> +#include <string> +#include <iostream> +#ifndef _WIN32 +#include <unistd.h> +#else +#include <windows.h> + +#define sleep(n) Sleep(n) +#endif + +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 (&request); + std::cout << "Received Hello" << std::endl; + + // Do some 'work' + sleep(1); + + // Send reply back to client + zmq::message_t reply (5); + memcpy (reply.data (), "World", 5); + socket.send (reply); + } + return 0; +} |