33 lines
855 B
C++
33 lines
855 B
C++
|
|
#include <expected>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <span>
|
|
#include <iostream>
|
|
|
|
#include <tcpclient.hpp>
|
|
|
|
int main( int argc, char** argv) {
|
|
TCPClient client;
|
|
auto res = client.Connect("209.51.188.116", 80);
|
|
if (!res) {
|
|
std::cerr << res.error() << std::endl;
|
|
return 1;
|
|
}
|
|
auto wSize = client.Write("GET / HTTP/1.1\n\n\n");
|
|
if (!wSize) {
|
|
std::cerr << wSize.error() << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
std::string buffer;
|
|
auto rSize = client.Read(buffer, 8);
|
|
if (!rSize) {
|
|
std::cerr << rSize.error() << std::endl;
|
|
return 1;
|
|
}
|
|
std::cout << std::format("read {} bytes", rSize.value()) << std::endl;
|
|
std::cout << std::format("{}", buffer) << std::endl;
|
|
|
|
}
|