History

add libzmq and cppzmq

Tony Theodore committed 8 years ago

Commit 90fc2211 parent 61587926 files · +179 −0Browse files

Showing the changes to src/cppzmq-test.cpp (1 of 6 files). Show all

Unified · Split

src/cppzmq-test.cpp+44−0
@@ -0,0 +1,44 @@
1/*
2 * This file is part of MXE. See LICENSE.md for licensing information.
3 */
4
5
6// Taken from: http://zguide.zeromq.org/cpp:hwserver
7// Hello World server in C++
8// Binds REP socket to tcp://*:5555
9// Expects "Hello" from client, replies with "World"
10//
11#include <zmq.hpp>
12#include <string>
13#include <iostream>
14#ifndef _WIN32
15#include <unistd.h>
16#else
17#include <windows.h>
18
19#define sleep(n) Sleep(n)
20#endif
21
22int main () {
23 // Prepare our context and socket
24 zmq::context_t context (1);
25 zmq::socket_t socket (context, ZMQ_REP);
26 socket.bind ("tcp://*:5555");
27
28 while (true) {
29 zmq::message_t request;
30
31 // Wait for next request from client
32 socket.recv (&request);
33 std::cout << "Received Hello" << std::endl;
34
35 // Do some 'work'
36 sleep(1);
37
38 // Send reply back to client
39 zmq::message_t reply (5);
40 memcpy (reply.data (), "World", 5);
41 socket.send (reply);
42 }
43 return 0;
44}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t