Files
stvpn/tcpclient_test.cpp
T
2026-04-23 14:53:39 +02:00

35 lines
909 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::vector<uint8_t> buffer;
buffer.resize(2048);
auto rSize = client.Read(&buffer);
if (!rSize) {
std::cerr << rSize.error() << std::endl;
return 1;
}
std::cout << rSize.value() << std::endl;
std::string s(buffer.begin(), buffer.end());
std::cout << std::format("{}", s) << std::endl;
}