File tree 4 files changed +70
-8
lines changed
4 files changed +70
-8
lines changed Original file line number Diff line number Diff line change @@ -53,18 +53,22 @@ int main()
53
53
sock.send(zmq::str_buffer("Hello, world"), zmq::send_flags::dontwait);
54
54
}
55
55
```
56
- This a more complex example where we send and receive multi-part messages.
56
+ This a more complex example where we send and receive multi-part messages over TCP with a wildcard port .
57
57
``` c++
58
58
#include < iostream>
59
59
#include < zmq_addon.hpp>
60
60
61
61
int main ()
62
62
{
63
63
zmq::context_t ctx;
64
- zmq::socket_t sock1(ctx, zmq::socket_type::pair);
65
- zmq::socket_t sock2(ctx, zmq::socket_type::pair);
66
- sock1.bind("inproc://test");
67
- sock2.connect("inproc://test");
64
+ zmq::socket_t sock1(ctx, zmq::socket_type::push);
65
+ zmq::socket_t sock2(ctx, zmq::socket_type::pull);
66
+ sock1.bind("tcp://127.0.0.1:*");
67
+ const std::string last_endpoint =
68
+ sock1.get(zmq::sockopt::last_endpoint);
69
+ std::cout << "Connecting to "
70
+ << last_endpoint << std::endl;
71
+ sock2.connect(last_endpoint);
68
72
69
73
std::array<zmq::const_buffer, 2> send_msgs = {
70
74
zmq::str_buffer ("foo"),
@@ -84,6 +88,8 @@ int main()
84
88
}
85
89
```
86
90
91
+ See the ` examples ` directory for more examples. When the project is compiled with tests enabled, each example gets compiled to an executable.
92
+
87
93
Compatibility Guidelines
88
94
========================
89
95
Original file line number Diff line number Diff line change @@ -15,9 +15,25 @@ add_executable(
15
15
pubsub_multithread_inproc
16
16
pubsub_multithread_inproc.cpp
17
17
)
18
-
19
18
target_link_libraries (
20
19
pubsub_multithread_inproc
21
- PRIVATE cppzmq
22
- PRIVATE ${CMAKE_THREAD_LIBS_INIT}
20
+ PRIVATE cppzmq ${CMAKE_THREAD_LIBS_INIT}
21
+ )
22
+
23
+ add_executable (
24
+ hello_world
25
+ hello_world.cpp
26
+ )
27
+ target_link_libraries (
28
+ hello_world
29
+ PRIVATE cppzmq ${CMAKE_THREAD_LIBS_INIT}
30
+ )
31
+
32
+ add_executable (
33
+ multipart_messages
34
+ multipart_messages.cpp
35
+ )
36
+ target_link_libraries (
37
+ multipart_messages
38
+ PRIVATE cppzmq ${CMAKE_THREAD_LIBS_INIT}
23
39
)
Original file line number Diff line number Diff line change
1
+ #include < zmq.hpp>
2
+
3
+ int main ()
4
+ {
5
+ zmq::context_t ctx;
6
+ zmq::socket_t sock (ctx, zmq::socket_type::push);
7
+ sock.bind (" inproc://test" );
8
+ sock.send (zmq::str_buffer (" Hello, world" ), zmq::send_flags::dontwait);
9
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < zmq_addon.hpp>
3
+
4
+ int main ()
5
+ {
6
+ zmq::context_t ctx;
7
+ zmq::socket_t sock1 (ctx, zmq::socket_type::push);
8
+ zmq::socket_t sock2 (ctx, zmq::socket_type::pull);
9
+ sock1.bind (" tcp://127.0.0.1:*" );
10
+ const std::string last_endpoint =
11
+ sock1.get (zmq::sockopt::last_endpoint);
12
+ std::cout << " Connecting to "
13
+ << last_endpoint << std::endl;
14
+ sock2.connect (last_endpoint);
15
+
16
+ std::array<zmq::const_buffer, 2 > send_msgs = {
17
+ zmq::str_buffer (" foo" ),
18
+ zmq::str_buffer (" bar!" )
19
+ };
20
+ if (!zmq::send_multipart (sock1, send_msgs))
21
+ return 1 ;
22
+
23
+ std::vector<zmq::message_t > recv_msgs;
24
+ const auto ret = zmq::recv_multipart (
25
+ sock2, std::back_inserter (recv_msgs));
26
+ if (!ret)
27
+ return 1 ;
28
+ std::cout << " Got " << *ret
29
+ << " messages" << std::endl;
30
+ return 0 ;
31
+ }
You can’t perform that action at this time.
0 commit comments