5int main(
int argc,
char **argv) {
7 std::cerr <<
"client: Invalid arguments\n"
8 << argv[0] <<
" <host> <port>\n";
16 if (sock.
connect(argv[1], argv[2])) {
18 std::cout <<
"enter data: ";
19 std::getline(std::cin, data);
20 if (sock.
write_all(data.c_str(), data.length()) > 0)
21 std::cout <<
"Sent " << data.length() <<
" bytes.\n";
23 std::cout <<
"client: Error connecting..\n";
26 std::cerr <<
"client: " << e.
text() <<
"\n";
Lightweight exception wrapper for MXNetwork failures.
std::string text() const
Return the stored error text.
C++ wrapper around the MXNetwork socket API.
ssize_t write_all(const void *buf, size_t bytes)
Write exactly the requested number of bytes.
bool connect(const std::string_view host, const std::string_view port)
Connect to a remote Internet endpoint.
void mx_socket_ignore_pipe_signal()
Ignore SIGPIPE on platforms that require it.
@ TYPE_INET
IPv4 stream socket.
RAII helper that initializes and shuts down the platform socket subsystem.