ZIO
Python and C++ interface to ZeroMQ and Zyre
test_port.cpp
Go to the documentation of this file.
1 #include "zio/port.hpp"
2 #include "zio/peer.hpp"
3 #include "zio/main.hpp"
4 #include "zio/logging.hpp"
5 
6 #include <iostream>
7 using namespace std;
8 
9 
10 int main()
11 {
12  zio::init_all();
13 
14  // this test generally pretends to be the guts of a node.
15 
16  // create many ports
17  zio::Port port("name1", ZMQ_PUB, "127.0.0.1");
18  port.bind("127.0.0.1",0);
19  //port.bind("tcp://127.0.0.1:5678");
20  // port.connect("name2", "portA");
21 
22  // bind all ports first, collecting their headers
23  auto hh = port.do_binds();
24  for (const auto& one : hh) {
25  zio::debug("test: not advertising bind: {} = {}",
26  one.first, one.second);
27  }
28 
29  // advertise those
30  zio::Peer peer("test_port", hh);
31 
32  // tell all ports to go online and give the peer so they can
33  // resovle any connects
34  port.online(peer);
35 
36  // for completeness
37  port.offline();
38 
39  return 0;
40 }
void online(Peer &peer)
Make any previously requested connections.
Definition: port.cpp:137
void offline()
Disconnect and unbind.
Definition: port.cpp:195
A port holds a socket in the context of a node.
Definition: port.hpp:27
int main()
Definition: test_port.cpp:10
void init_all()
Definition: main.cpp:22
void bind()
Request a default bind.
Definition: port.cpp:69
headerset_t do_binds()
Perform any requested binds.
Definition: port.cpp:113
Peer at the network to discover peers and advertise self.
Definition: peer.hpp:44