Skip to content

Commit

Permalink
Add a more complex example involving multi-part messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gummif committed Oct 26, 2019
1 parent 505edeb commit c9225c1
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ Supported platforms

Examples
========
This example requires at least C++11.
These examples requires at least C++11.
```c++
#include <string>
#include <zmq.hpp>

int main()
Expand All @@ -54,6 +53,36 @@ int main()
sock.send(zmq::str_buffer("Hello, world"), zmq::send_flags::dontwait);
}
```
This a more complex example where we send and receive multi-part messages.
```c++
#include <iostream>
#include <zmq_addon.hpp>

int main()
{
zmq::context_t ctx;
zmq::socket_t sock1(ctx, zmq::socket_type::pair);
zmq::socket_t sock2(ctx, zmq::socket_type::pair);
sock1.bind("inproc://test");
sock2.connect("inproc://test");

std::array<zmq::const_buffer, 2> send_msgs = {
zmq::str_buffer("foo"),
zmq::str_buffer("bar!")
};
if (!zmq::send_multipart(sock1, send_msgs))
return 1;

std::vector<zmq::message_t> recv_msgs;
const auto ret = zmq::recv_multipart(
sock2, std::back_inserter(recv_msgs));
if (!ret)
return 1;
std::cout << "Got " << *ret
<< " messages" << std::endl;
return 0;
}
```

Contribution policy
===================
Expand Down

0 comments on commit c9225c1

Please sign in to comment.