#include "edge.hpp" int main() { edge::io_context ioc; edge::tcp_acceptor acceptor{ioc, { edge::ipv4::addr::any(), 8080 }}; edge::async_accept(acceptor, [](edge::tcp_socket socket) { edge::async_write(socket, edge::buffer("Hello, world!"), [](edge::error_code ec, size_t) { if (ec) { std::cerr << "Failed to write data: " << ec.message() << std::endl; } }); }); ioc.run(); return 0; }
#include "edge.hpp" int main() { edge::io_context ioc; edge::tcp_socket socket{ioc}; edge::async_connect(socket, { edge::ipv4::addr::loopback(), 8080 }, [](edge::error_code ec) { if (!ec) { char buf[1024]; edge::async_read(socket, edge::buffer(buf), [](edge::error_code ec, size_t n) { if (!ec) { std::cout << "Received " << n << " bytes: " << buf << std::endl; } else { std::cerr << "Failed to read data: " << ec.message() << std::endl; } }); } else { std::cerr << "Failed to connect: " << ec.message() << std::endl; } }); ioc.run(); return 0; }This code snippet sets up a client that connects to the same server running on port 8080. Once the connection is established, the client reads a message sent by the server and outputs it to the console. Cpp Edge is an open-source package library that is available under the MIT license.