38 namespace communication {
40 boost::asio::io_service& io_service,
41 const boost::asio::ip::address_v4& server_ip,
42 const uint16_t& server_port)
43 : m_packet_handler(packet_handler)
44 , m_io_service(io_service)
53 catch (
const std::exception& e)
55 ROS_ERROR(
"Exception while creating socket: %s", e.what());
66 boost::system::error_code ec;
67 m_socket_ptr->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
68 if (ec != boost::system::errc::success)
70 ROS_ERROR(
"Error shutting socket down: %i", ec.value());
74 ROS_INFO(
"TCP Connection successfully shutdown");
78 if (ec != boost::system::errc::success)
80 ROS_ERROR(
"Error closing Socket: %i", ec.value());
84 ROS_INFO(
"TCP Socket successfully closed.");
93 if (ec != boost::system::errc::success)
95 ROS_ERROR(
"TCP error code: %i", ec.value());
99 ROS_INFO(
"TCP connection successfully established.");
116 boost::asio::buffer(sendBuffer),
117 [
this](boost::system::error_code ec, std::size_t bytes_send) {
130 [
this](boost::system::error_code ec, std::size_t bytes_recvd) {
141 const std::size_t& bytes_transferred)
144 if (!error || error == boost::asio::error::message_size)
150 ROS_ERROR(
"Error in tcp handle send and receive: %i", error.value());
158 const std::size_t& bytes_transferred)
167 ROS_ERROR(
"Error in tcp handle receive: %i", error.value());