networks-1.cpp/main.cpp

38 lines
1.0 KiB
C++

import std;
import ru.landgrafhomyak.BGTU.networks_1.exceptions;
import ru.landgrafhomyak.BGTU.networks_1.threads;
import ru.landgrafhomyak.BGTU.networks_1.sockets;
int main() {
LdH::run_catching_main([] {
LdH::Sockets::init_sockets();
std::cout << LdH::Sockets::Address::parse("google.com", "443").to_string() << std::endl;
std::cout << LdH::Sockets::Address::parse("localhost123123", "443").to_string() << std::endl;
auto server = LdH::Sockets::listen_udp(LdH::Sockets::Address::parse("127.0.0.2", "8081"));
auto server_thread = LdH::fork("server", [&] {
char buffer[10];
server.recvOneTruncating(10, buffer);
std::cout << buffer << std::endl;
server.close();
});
auto client_thread = LdH::fork("client", [&] {
auto client = LdH::Sockets::connect_udp(LdH::Sockets::Address::parse("127.0.0.2", "8081"));
char buffer[10] = "hello\n";
client.sendOne(10, buffer);
client.close();
});
server_thread.join();
client_thread.join();
server_thread.destroy();
client_thread.destroy();
LdH::Sockets::deinit_sockets();
});
}