Helper for asynchronously sending and receiving data via UDP. More...
#include <udp_client.h>
Classes | |
class | CloseConnectionFailure |
Exception thrown if the UDP socket cannot be closed. More... | |
class | OpenConnectionFailure |
Exception thrown if the UDP socket cannot be opened. More... | |
Public Member Functions | |
void | close () |
Closes the UDP connection and stops all pending asynchronous operation. More... | |
boost::asio::ip::address_v4 | hostIp () |
Returns local ip address of current socket connection. More... | |
void | startAsyncReceiving (const ReceiveMode &modi=ReceiveMode::continuous) |
Starts an asynchronous process listing to (a) new message(s) from the other endpoint. If the function continuously listens to new messages or only listens for one message is specified by the receive modi specified. More... | |
void | stop () |
Stops the underlying io_service so that no messages are received anymore. More... | |
UdpClientImpl (const NewMessageCallback &msg_callback, const ErrorCallback &error_callback, const unsigned short &host_port, const unsigned int &endpoint_ip, const unsigned short &endpoint_port) | |
Opens an UDP connection. More... | |
void | write (const data_conversion_layer::RawData &data) |
Asynchronously sends the specified data to the other endpoint. More... | |
~UdpClientImpl () | |
Closes the UDP connection and stops all pending asynchronous operation. More... | |
Private Member Functions | |
void | asyncReceive (const ReceiveMode &modi) |
void | sendCompleteHandler (const boost::system::error_code &error, std::size_t bytes_transferred) |
Private Attributes | |
boost::asio::ip::udp::endpoint | endpoint_ |
ErrorCallback | error_callback_ |
boost::asio::io_service | io_service_ |
std::thread | io_service_thread_ |
NewMessageCallback | message_callback_ |
data_conversion_layer::RawDataPtr | received_data_ |
boost::asio::ip::udp::socket | socket_ |
boost::asio::io_service::work | work_ { io_service_ } |
Helper for asynchronously sending and receiving data via UDP.
This class provides methods for opening and closing the UDP connection, writing and receiving data via UDP. The data is represented by data_conversion_layer::RawData. Upon receiving data a NewMessageCallback is invoked. When something goes wrong an ErrorCallback is invoked.
The ScannerV2 constructs two UDP clients, which are then used by the scanner_protocol::ScannerProtocolDef.
Definition at line 74 of file udp_client.h.
|
inline |
Opens an UDP connection.
msg_callback | Callback called whenever new messages are received. |
error_callback | Handler called whenever something wents wrong while receiving data. |
host_port | Port from which data are sent and received. |
endpoint_ip | IP address of the endpoint from which data are received and sent too. |
endpoint_port | Port on which the other endpoint is sending and receiving data. |
Definition at line 175 of file udp_client.h.
|
inline |
Closes the UDP connection and stops all pending asynchronous operation.
Definition at line 247 of file udp_client.h.
|
inlineprivate |
Definition at line 300 of file udp_client.h.
|
inline |
Closes the UDP connection and stops all pending asynchronous operation.
Definition at line 217 of file udp_client.h.
|
inline |
Returns local ip address of current socket connection.
Definition at line 242 of file udp_client.h.
|
inlineprivate |
Definition at line 262 of file udp_client.h.
|
inline |
Starts an asynchronous process listing to (a) new message(s) from the other endpoint. If the function continuously listens to new messages or only listens for one message is specified by the receive modi specified.
modi | Specifies if the function continuously listens to new messages or or not. |
Definition at line 286 of file udp_client.h.
|
inline |
Stops the underlying io_service so that no messages are received anymore.
Note: In contrary to close() this is non-blocking but note that after calling stop() calls to the msg_callback are still possible due to pending messages.
Definition at line 212 of file udp_client.h.
|
inline |
Asynchronously sends the specified data to the other endpoint.
data | Data which have to be send to the other endpoint. |
Definition at line 275 of file udp_client.h.
|
private |
Definition at line 172 of file udp_client.h.
|
private |
Definition at line 169 of file udp_client.h.
|
private |
Definition at line 161 of file udp_client.h.
|
private |
Definition at line 164 of file udp_client.h.
|
private |
Definition at line 168 of file udp_client.h.
|
private |
Definition at line 166 of file udp_client.h.
|
private |
Definition at line 171 of file udp_client.h.
|
private |
Definition at line 163 of file udp_client.h.