File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -41,9 +41,8 @@ Supported platforms
41
41
42
42
Examples
43
43
========
44
- This example requires at least C++11.
44
+ These examples requires at least C++11.
45
45
``` c++
46
- #include < string>
47
46
#include < zmq.hpp>
48
47
49
48
int main ()
@@ -54,6 +53,36 @@ int main()
54
53
sock.send(zmq::str_buffer("Hello, world"), zmq::send_flags::dontwait);
55
54
}
56
55
```
56
+ This a more complex example where we send and receive multi-part messages.
57
+ ``` c++
58
+ #include < iostream>
59
+ #include < zmq_addon.hpp>
60
+
61
+ int main ()
62
+ {
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");
68
+
69
+ std::array<zmq::const_buffer, 2> send_msgs = {
70
+ zmq::str_buffer ("foo"),
71
+ zmq::str_buffer("bar!")
72
+ };
73
+ if (!zmq::send_multipart(sock1, send_msgs))
74
+ return 1;
75
+
76
+ std::vector<zmq::message_t> recv_msgs;
77
+ const auto ret = zmq::recv_multipart(
78
+ sock2, std::back_inserter(recv_msgs));
79
+ if (!ret)
80
+ return 1;
81
+ std::cout << "Got " << *ret
82
+ << " messages" << std::endl;
83
+ return 0;
84
+ }
85
+ ```
57
86
58
87
Contribution policy
59
88
===================
You can’t perform that action at this time.
0 commit comments