MCPcopy Create free account
hub / github.com/davisking/dlib / run_example_1

Function run_example_1

examples/bridge_ex.cpp:76–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74// ----------------------------------------------------------------------------------------
75
76void run_example_1(
77)
78{
79 cout << "\n ---- Running example 1 ---- " << endl;
80
81 /*
82 The idea of the bridge is basically to allow two different dlib::pipe objects
83 to be connected together via a TCP connection. This is best illustrated by
84 the following short example. In it we create two pipes, in and out. When
85 an object is enqueued into the out pipe it will be automatically sent
86 through a TCP connection and once received at the other end it will be
87 inserted into the in pipe.
88 */
89 dlib::pipe<int> in(4), out(4);
90
91
92 // This bridge will listen on port 12345 for an incoming TCP connection. Then
93 // it will read data from that connection and put it into the in pipe.
94 bridge b2(listen_on_port(12345), receive(in));
95
96 // This bridge will initiate a TCP connection and then start dequeuing
97 // objects from out and transmitting them over the connection.
98 bridge b1(connect_to_ip_and_port("127.0.0.1", 12345), transmit(out));
99
100 // As an aside, in a real program, each of these bridges and pipes would be in a
101 // separate application. But to make this example self contained they are both
102 // right here.
103
104
105
106 // Now let's put some things into the out pipe
107 int value = 1;
108 out.enqueue(value);
109
110 value = 2;
111 out.enqueue(value);
112
113 value = 3;
114 out.enqueue(value);
115
116
117 // Now those 3 ints can be dequeued from the in pipe. They will show up
118 // in the same order they were inserted into the out pipe.
119 in.dequeue(value);
120 cout << "dequeued value: "<< value << endl;
121 in.dequeue(value);
122 cout << "dequeued value: "<< value << endl;
123 in.dequeue(value);
124 cout << "dequeued value: "<< value << endl;
125}
126
127// ----------------------------------------------------------------------------------------
128// ----------------------------------------------------------------------------------------

Callers 1

mainFunction · 0.85

Calls 5

receiveFunction · 0.85
transmitFunction · 0.85
listen_on_portClass · 0.50
enqueueMethod · 0.45

Tested by

no test coverage detected