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

Function main

examples++/http.cpp:9–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7// on STREAM sockets
8
9int main(void) {
10 using std::string;
11
12 using libsocket::inet_stream;
13
14 try {
15 string host = "spheniscida.de";
16 string port = "80";
17 string answer;
18 string request1("GET / HTTP/1.1\n");
19 string request2("Host: spheniscida.de\n\n");
20
21 libsocket::inet_stream sock(host, port, LIBSOCKET_IPv4, 0);
22
23 sock << request1 << request2;
24
25 sock.shutdown(LIBSOCKET_WRITE);
26
27 answer.resize(2000);
28
29 while (answer.size() > 0) {
30 sock >> answer;
31
32 std::cout << answer;
33 }
34
35 // sock.destroy(); // socket is also destroyed by the destructor
36 } catch (const libsocket::socket_exception& exc) {
37 std::cerr << exc.mesg;
38 }
39
40 return 0;
41}

Callers

nothing calls this directly

Calls 1

shutdownMethod · 0.80

Tested by

no test coverage detected