| 12 | // message. |
| 13 | |
| 14 | int main(void) { |
| 15 | using libsocket::unix_stream_client; |
| 16 | using libsocket::unix_stream_server; |
| 17 | using std::string; |
| 18 | |
| 19 | string bindpath = "/tmp/unixsocket"; |
| 20 | char* answer = new char[128]; |
| 21 | |
| 22 | memset(answer, 0, 128); |
| 23 | |
| 24 | try { |
| 25 | unix_stream_server srv(bindpath); |
| 26 | |
| 27 | unique_ptr<unix_stream_client> client; |
| 28 | client = srv.accept2(); |
| 29 | |
| 30 | client->rcv(answer, 127); |
| 31 | // Alternatively: |
| 32 | // string xyz; |
| 33 | // xyz.resize(127); |
| 34 | //*client >> xyz; |
| 35 | |
| 36 | std::cout << answer; |
| 37 | |
| 38 | *client << "Hello back from server!\n"; |
| 39 | |
| 40 | } catch (const libsocket::socket_exception& exc) { |
| 41 | std::cerr << exc.mesg; |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |