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

Function main

examples++/http_2.cpp:8–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6// HTTP client demonstrating the use of snd and rcv on STREAM sockets
7
8int main(void) {
9 using std::string;
10
11 string host = "spheniscida.de";
12 string port = "80";
13 ssize_t len;
14 string test;
15
16 char* buf = new char[10000];
17
18 try {
19 libsocket::inet_stream sock(host.c_str(), port.c_str(), LIBSOCKET_IPv4);
20
21 sock.snd("GET / HTTP/1.0\n\n", 16);
22
23 sock.shutdown(LIBSOCKET_WRITE);
24
25 while (0 != (len = sock.rcv(buf, 10000)))
26 std::cout << string(
27 buf, len); // write only as many characters as we read
28 } catch (const libsocket::socket_exception& exc) {
29 std::cerr << exc.mesg;
30 }
31
32 return 0;
33}

Callers

nothing calls this directly

Calls 3

shutdownMethod · 0.80
sndMethod · 0.45
rcvMethod · 0.45

Tested by

no test coverage detected