MCPcopy Create free account
hub / github.com/dermesser/libsocket / main

Function main

examples++/echo_client_conn.cpp:10–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8 */
9
10int main(void) {
11 using std::string;
12
13 string host = "localhost";
14 string port = "1234";
15
16 string answer;
17
18 answer.resize(32);
19
20 libsocket::inet_dgram_client sock(LIBSOCKET_IPv4);
21
22 try {
23 std::cout << sock.gethost();
24 } catch (const libsocket::socket_exception& exc) {
25 std::cerr << exc.mesg;
26 }
27
28 try {
29 for (int i = 0; i < 20; i++) {
30 sock.connect(host, port);
31
32 sock << "Hello, server";
33
34 sock >> answer;
35
36 std::cout << "Answer from server: " << answer << std::endl;
37
38 sock.deconnect();
39 }
40 } catch (const libsocket::socket_exception& exc) {
41 std::cerr << exc.mesg;
42 }
43
44 sock.destroy();
45
46 return 0;
47}

Callers

nothing calls this directly

Calls 3

destroyMethod · 0.80
connectMethod · 0.45
deconnectMethod · 0.45

Tested by

no test coverage detected