39 namespace communication {
41 boost::asio::io_service& io_service,
42 const uint16_t& local_port)
43 : m_packet_handler(packet_handler)
45 , m_io_service(io_service)
51 m_socket_ptr = std::make_shared<boost::asio::ip::udp::socket>(
53 boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), local_port));
55 catch (std::exception& e)
57 ROS_ERROR(
"Exception while creating socket: %s", e.what());
71 [
this](boost::system::error_code ec, std::size_t bytes_recvd) {
77 const std::size_t& bytes_transferred)
86 ROS_ERROR(
"Error in UDP handle receive: %i", error.value());
AsyncUDPClient(PacketHandler packet_handler, boost::asio::io_service &io_service, const uint16_t &local_port=0)
Constructor of the asynchronous udp client.
A packetbuffer for the raw data from the sensor.
void handleReceive(const boost::system::error_code &error, const std::size_t &bytes_transferred)
boost::asio::ip::udp::endpoint m_remote_endpoint
void runService()
Start the listening loop for the udp data packets.
PacketHandler m_packet_handler
std::shared_ptr< boost::asio::ip::udp::socket > m_socket_ptr
boost::asio::io_service & m_io_service
datastructure::PacketBuffer::ArrayBuffer m_recv_buffer
boost::function< void(const sick::datastructure::PacketBuffer &)> PacketHandler
Typedef to a reference to a function. Will be used to process the incoming packets.
virtual ~AsyncUDPClient()
The destructor of the asynchronous udp client.
std::shared_ptr< boost::asio::io_service::work > m_io_work_ptr
unsigned short get_local_port()
Returns the actual port assigned to the local machine.