| 129 | // ---------------------------------------------------------------------------------------- |
| 130 | |
| 131 | void run_example_2( |
| 132 | ) |
| 133 | { |
| 134 | cout << "\n ---- Running example 2 ---- " << endl; |
| 135 | |
| 136 | /* |
| 137 | This example makes a simple echo server on port 12345. When an object |
| 138 | is inserted into the out pipe it will be sent over a TCP connection, get |
| 139 | put into the echo pipe and then immediately read out of the echo pipe and |
| 140 | sent back over the TCP connection where it will finally be placed into the in |
| 141 | pipe. |
| 142 | */ |
| 143 | |
| 144 | dlib::pipe<int> in(4), out(4), echo(4); |
| 145 | |
| 146 | // Just like TCP connections, a bridge can send data both directions. The directionality |
| 147 | // of a pipe is indicated by the receive() and transmit() type decorations. Also, the order |
| 148 | // they are listed doesn't matter. |
| 149 | bridge echo_bridge(listen_on_port(12345), receive(echo), transmit(echo)); |
| 150 | |
| 151 | // Note that you can also specify the ip and port as a string by using connect_to(). |
| 152 | bridge b1(connect_to("127.0.0.1:12345"), transmit(out), receive(in)); |
| 153 | |
| 154 | |
| 155 | int value = 1; |
| 156 | out.enqueue(value); |
| 157 | |
| 158 | value = 2; |
| 159 | out.enqueue(value); |
| 160 | |
| 161 | value = 3; |
| 162 | out.enqueue(value); |
| 163 | |
| 164 | |
| 165 | in.dequeue(value); |
| 166 | cout << "dequeued value: "<< value << endl; |
| 167 | in.dequeue(value); |
| 168 | cout << "dequeued value: "<< value << endl; |
| 169 | in.dequeue(value); |
| 170 | cout << "dequeued value: "<< value << endl; |
| 171 | } |
| 172 | |
| 173 | // ---------------------------------------------------------------------------------------- |
| 174 | // ---------------------------------------------------------------------------------------- |
no test coverage detected