23 #include "goby/common/logger.h" 24 #include "goby/util/as.h" 26 #include "tcp_client.h" 29 const std::string& delimiter ,
32 socket_(io_service_), server_(server), port_(as<
std::string>(port))
36 bool goby::util::TCPClient::start_specific()
41 boost::asio::ip::tcp::resolver resolver(io_service_);
42 boost::asio::ip::tcp::resolver::query query(
43 server_, port_, boost::asio::ip::resolver_query_base::numeric_service);
45 boost::system::error_code resolver_error = boost::asio::error::host_not_found;
46 boost::asio::ip::tcp::resolver::iterator endpoint_iterator =
47 resolver.resolve(query, resolver_error);
50 glog.is(WARN) &&
glog <<
"Error resolving address: " << server_ <<
":" << port_ <<
": " 51 << resolver_error.message() << std::endl;
55 boost::asio::ip::tcp::resolver::iterator end;
57 boost::system::error_code error = boost::asio::error::host_not_found;
58 while (error && endpoint_iterator != end)
61 socket_.connect(*endpoint_iterator++, error);
65 glog.is(WARN) &&
glog <<
"Error connecting to address: " << server_ <<
":" << port_ <<
": " 66 << error.message() << std::endl;
68 return error ?
false :
true;
common::FlexOstream glog
Access the Goby logger through this object.
TCPClient(const std::string &server, unsigned port, const std::string &delimiter="\r\n", int retry_interval=10)
create a TCPClient