88 boost::asio::ip::tcp::resolver tcpresolver(io_service);
89 boost::asio::ip::tcp::resolver::query tcpquery(server_adress, std::to_string(tcp_port));
90 boost::asio::ip::tcp::resolver::iterator it = tcpresolver.resolve(tcpquery);
91 boost::system::error_code errorcode;
92 m_tcp_socket.connect(*it, errorcode);
94 if(!errorcode && m_tcp_socket.is_open())
97 boost::system::error_code socket_option_errorcodes[3];
98 boost::asio::ip::tcp::no_delay socket_option_no_delay;
99 boost::asio::socket_base::send_buffer_size socket_option_send_buffer_size;
100 boost::asio::socket_base::receive_buffer_size socket_option_receive_buffer_size;
102 m_tcp_socket.get_option(socket_option_no_delay, socket_option_errorcodes[0]);
103 m_tcp_socket.get_option(socket_option_send_buffer_size, socket_option_errorcodes[1]);
104 m_tcp_socket.get_option(socket_option_receive_buffer_size, socket_option_errorcodes[2]);
106 if (socket_option_errorcodes[0] || socket_option_no_delay.value() ==
false)
107 m_tcp_socket.set_option(boost::asio::ip::tcp::no_delay(
true), socket_option_errorcodes[0]);
108 if (socket_option_errorcodes[1] || socket_option_send_buffer_size.value() < 64 * 1024)
109 m_tcp_socket.set_option(boost::asio::socket_base::send_buffer_size(64 * 1024), socket_option_errorcodes[1]);
110 if (socket_option_errorcodes[2] || socket_option_receive_buffer_size.value() < 64 * 1024)
111 m_tcp_socket.set_option(boost::asio::socket_base::receive_buffer_size(64 * 1024), socket_option_errorcodes[2]);
113 m_tcp_socket.get_option(socket_option_no_delay, socket_option_errorcodes[0]);
114 m_tcp_socket.get_option(socket_option_send_buffer_size, socket_option_errorcodes[1]);
115 m_tcp_socket.get_option(socket_option_receive_buffer_size, socket_option_errorcodes[2]);
117 if(socket_option_errorcodes[0] || socket_option_errorcodes[1] || socket_option_errorcodes[2])
119 ROS_WARN_STREAM(
"## ClientSocket::connect(): socket connected to " << server_adress <<
":" << tcp_port <<
", but socket::get_option() failed, "
120 <<
" socket options error messages: no_delay=" << socket_option_errorcodes[0].message() <<
", send_buffer_size=" << socket_option_errorcodes[1].message()
121 <<
", receive_buffer_size=" << socket_option_errorcodes[2].message());
123 ROS_INFO_STREAM(
"ClientSocket::connect(): socket connected to " << server_adress <<
":" << tcp_port <<
", socket options values: no_delay=" << socket_option_no_delay.value()
124 <<
", send_buffer_size=" << socket_option_send_buffer_size.value() <<
", receive_buffer_size=" << socket_option_receive_buffer_size.value());
128 ROS_WARN_STREAM(
"ClientSocket::connect(): no connection to localization controller " << server_adress <<
":" << tcp_port <<
", error " << errorcode.value() <<
" \"" << errorcode.message() <<
"\"");
133 catch(std::exception & exc)
135 ROS_WARN_STREAM(
"## ERROR ClientSocket::connect(): connect to " << server_adress <<
":" << tcp_port <<
" failed, exception " << exc.what());
150 if (force_shutdown || m_tcp_socket.is_open())
152 m_tcp_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
153 m_tcp_socket.close();
157 catch(std::exception & exc)
159 ROS_WARN_STREAM(
"ColaTransmitter::closeTcpConnections(): exception " << exc.what() <<
" on closing connection.");