Updated TCP echo clients to show/test connector construction.

This commit is contained in:
fpagliughi
2019-08-10 12:25:03 -04:00
parent c27e8df153
commit f47d8e8a3b
3 changed files with 15 additions and 9 deletions

View File

@@ -48,12 +48,14 @@ int main(int argc, char* argv[])
in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345;
sockpp::socket_initializer sockInit;
sockpp::tcp6_connector conn;
auto addr = sockpp::inet6_address(host, port);
// Implicitly creates an inet6_address from {host,port}
// and then tries the connection.
if (!conn.connect(addr)) {
cerr << "Error connecting to server at " << addr
sockpp::tcp6_connector conn({host, port});
if (!conn) {
cerr << "Error connecting to server at "
<< sockpp::inet6_address(host, port)
<< "\n\t" << conn.last_error_str() << endl;
return 1;
}

View File

@@ -47,11 +47,15 @@ int main(int argc, char* argv[])
string host = (argc > 1) ? argv[1] : "localhost";
in_port_t port = (argc > 2) ? atoi(argv[2]) : 12345;
sockpp::socket_initializer sockInit;
sockpp::tcp_connector conn;
sockpp::socket_initializer sockInit;
if (!conn.connect(sockpp::inet_address(host, port))) {
cerr << "Error connecting to server at " << host << ":" << port
// Implicitly creates an inet_address from {host,port}
// and then tries the connection.
sockpp::tcp_connector conn({host, port});
if (!conn) {
cerr << "Error connecting to server at "
<< sockpp::inet_address(host, port)
<< "\n\t" << conn.last_error_str() << endl;
return 1;
}