|
CppServer 1.0.5.0
C++ Server Library
|
UDP client. More...
#include <udp_client.h>
Public Member Functions | |
| UDPClient (const std::shared_ptr< Service > &service, const std::string &address, int port) | |
| Initialize UDP client with a given Asio service, server address and port number. | |
| UDPClient (const std::shared_ptr< Service > &service, const std::string &address, const std::string &scheme) | |
| Initialize UDP client with a given Asio service, server address and scheme name. | |
| UDPClient (const std::shared_ptr< Service > &service, const asio::ip::udp::endpoint &endpoint) | |
| Initialize UDP client with a given Asio service and endpoint. | |
| UDPClient (const UDPClient &)=delete | |
| UDPClient (UDPClient &&)=delete | |
| virtual | ~UDPClient ()=default |
| UDPClient & | operator= (const UDPClient &)=delete |
| UDPClient & | operator= (UDPClient &&)=delete |
| const CppCommon::UUID & | id () const noexcept |
| Get the client Id. | |
| std::shared_ptr< Service > & | service () noexcept |
| Get the Asio service. | |
| std::shared_ptr< asio::io_service > & | io_service () noexcept |
| Get the Asio IO service. | |
| asio::io_service::strand & | strand () noexcept |
| Get the Asio service strand for serialized handler execution. | |
| asio::ip::udp::endpoint & | endpoint () noexcept |
| Get the client endpoint. | |
| asio::ip::udp::socket & | socket () noexcept |
| Get the client socket. | |
| const std::string & | address () const noexcept |
| Get the server address. | |
| const std::string & | scheme () const noexcept |
| Get the scheme name. | |
| int | port () const noexcept |
| Get the server port number. | |
| uint64_t | bytes_pending () const noexcept |
| Get the number of bytes pending sent by the client. | |
| uint64_t | bytes_sent () const noexcept |
| Get the number of bytes sent by the client. | |
| uint64_t | bytes_received () const noexcept |
| Get the number of bytes received by the client. | |
| uint64_t | datagrams_sent () const noexcept |
| Get the number datagrams sent by the client. | |
| uint64_t | datagrams_received () const noexcept |
| Get the number datagrams received by the client. | |
| bool | option_reuse_address () const noexcept |
| Get the option: reuse address. | |
| bool | option_reuse_port () const noexcept |
| Get the option: reuse port. | |
| bool | option_multicast () const noexcept |
| Get the option: bind the socket to the multicast UDP server. | |
| size_t | option_receive_buffer_limit () const noexcept |
| Get the option: receive buffer limit. | |
| size_t | option_receive_buffer_size () const |
| Get the option: receive buffer size. | |
| size_t | option_send_buffer_limit () const noexcept |
| Get the option: send buffer limit. | |
| size_t | option_send_buffer_size () const |
| Get the option: send buffer size. | |
| bool | IsConnected () const noexcept |
| Is the client connected? | |
| virtual bool | Connect () |
| Connect the client (synchronous) | |
| virtual bool | Connect (const std::shared_ptr< UDPResolver > &resolver) |
| Connect the client using the given DNS resolver (synchronous) | |
| virtual bool | Disconnect () |
| Disconnect the client (synchronous) | |
| virtual bool | Reconnect () |
| Reconnect the client (synchronous) | |
| virtual bool | ConnectAsync () |
| Connect the client (asynchronous) | |
| virtual bool | ConnectAsync (const std::shared_ptr< UDPResolver > &resolver) |
| Connect the client using the given DNS resolver (asynchronous) | |
| virtual bool | DisconnectAsync () |
| Disconnect the client (asynchronous) | |
| virtual bool | ReconnectAsync () |
| Reconnect the client (asynchronous) | |
| virtual void | JoinMulticastGroup (const std::string &address) |
| Join multicast group with a given address (synchronous) | |
| virtual void | LeaveMulticastGroup (const std::string &address) |
| Leave multicast group with a given address (synchronous) | |
| virtual void | JoinMulticastGroupAsync (const std::string &address) |
| Join multicast group with a given address (asynchronous) | |
| virtual void | LeaveMulticastGroupAsync (const std::string &address) |
| Leave multicast group with a given address (asynchronous) | |
| virtual size_t | Send (const void *buffer, size_t size) |
| Send datagram to the connected server (synchronous) | |
| virtual size_t | Send (std::string_view text) |
| Send text to the connected server (synchronous) | |
| virtual size_t | Send (const asio::ip::udp::endpoint &endpoint, const void *buffer, size_t size) |
| Send datagram to the given endpoint (synchronous) | |
| virtual size_t | Send (const asio::ip::udp::endpoint &endpoint, std::string_view text) |
| Send text to the given endpoint (synchronous) | |
| virtual size_t | Send (const void *buffer, size_t size, const CppCommon::Timespan &timeout) |
| Send datagram to the connected server with timeout (synchronous) | |
| virtual size_t | Send (std::string_view text, const CppCommon::Timespan &timeout) |
| Send text to the connected server with timeout (synchronous) | |
| virtual size_t | Send (const asio::ip::udp::endpoint &endpoint, const void *buffer, size_t size, const CppCommon::Timespan &timeout) |
| Send datagram to the given endpoint with timeout (synchronous) | |
| virtual size_t | Send (const asio::ip::udp::endpoint &endpoint, std::string_view text, const CppCommon::Timespan &timeout) |
| Send text to the given endpoint with timeout (synchronous) | |
| virtual bool | SendAsync (const void *buffer, size_t size) |
| Send datagram to the connected server (asynchronous) | |
| virtual bool | SendAsync (std::string_view text) |
| Send text to the connected server (asynchronous) | |
| virtual bool | SendAsync (const asio::ip::udp::endpoint &endpoint, const void *buffer, size_t size) |
| Send datagram to the given endpoint (asynchronous) | |
| virtual bool | SendAsync (const asio::ip::udp::endpoint &endpoint, std::string_view text) |
| Send text to the given endpoint (asynchronous) | |
| virtual size_t | Receive (asio::ip::udp::endpoint &endpoint, void *buffer, size_t size) |
| Receive datagram from the given endpoint (synchronous) | |
| virtual std::string | Receive (asio::ip::udp::endpoint &endpoint, size_t size) |
| Receive text from the given endpoint (synchronous) | |
| virtual size_t | Receive (asio::ip::udp::endpoint &endpoint, void *buffer, size_t size, const CppCommon::Timespan &timeout) |
| Receive datagram from the given endpoint with timeout (synchronous) | |
| virtual std::string | Receive (asio::ip::udp::endpoint &endpoint, size_t size, const CppCommon::Timespan &timeout) |
| Receive text from the given endpoint with timeout (synchronous) | |
| virtual void | ReceiveAsync () |
| Receive datagram from the server (asynchronous) | |
| void | SetupReuseAddress (bool enable) noexcept |
| Setup option: reuse address. | |
| void | SetupReusePort (bool enable) noexcept |
| Setup option: reuse port. | |
| void | SetupMulticast (bool enable) noexcept |
| Setup option: bind the socket to the multicast UDP server. | |
| void | SetupReceiveBufferLimit (size_t limit) noexcept |
| Setup option: receive buffer limit. | |
| void | SetupReceiveBufferSize (size_t size) |
| Setup option: receive buffer size. | |
| void | SetupSendBufferLimit (size_t limit) noexcept |
| Setup option: send buffer limit. | |
| void | SetupSendBufferSize (size_t size) |
| Setup option: send buffer size. | |
Protected Member Functions | |
| virtual void | onConnected () |
| Handle client connected notification. | |
| virtual void | onDisconnected () |
| Handle client disconnected notification. | |
| virtual void | onJoinedMulticastGroup (const std::string &address) |
| Handle client joined multicast group notification. | |
| virtual void | onLeftMulticastGroup (const std::string &address) |
| Handle client left multicast group notification. | |
| virtual void | onReceived (const asio::ip::udp::endpoint &endpoint, const void *buffer, size_t size) |
| Handle datagram received notification. | |
| virtual void | onSent (const asio::ip::udp::endpoint &endpoint, size_t sent) |
| Handle datagram sent notification. | |
| virtual void | onError (int error, const std::string &category, const std::string &message) |
| Handle error notification. | |
UDP client.
UDP client is used to read/write datagrams from/into the connected UDP server.
Thread-safe.
Definition at line 29 of file udp_client.h.
| CppServer::Asio::UDPClient::UDPClient | ( | const std::shared_ptr< Service > & | service, |
| const std::string & | address, | ||
| int | port | ||
| ) |
Initialize UDP client with a given Asio service, server address and port number.
| service | - Asio service |
| address | - Server address |
| port | - Server port number |
Definition at line 14 of file udp_client.cpp.
| CppServer::Asio::UDPClient::UDPClient | ( | const std::shared_ptr< Service > & | service, |
| const std::string & | address, | ||
| const std::string & | scheme | ||
| ) |
Initialize UDP client with a given Asio service, server address and scheme name.
| service | - Asio service |
| address | - Server address |
| scheme | - Scheme name |
Definition at line 41 of file udp_client.cpp.
| CppServer::Asio::UDPClient::UDPClient | ( | const std::shared_ptr< Service > & | service, |
| const asio::ip::udp::endpoint & | endpoint | ||
| ) |
Initialize UDP client with a given Asio service and endpoint.
| service | - Asio service |
| endpoint | - Server UDP endpoint |
Definition at line 69 of file udp_client.cpp.
|
delete |
|
virtualdefault |
|
inlinenoexcept |
Get the server address.
Definition at line 74 of file udp_client.h.
|
inlinenoexcept |
Get the number of bytes pending sent by the client.
Definition at line 81 of file udp_client.h.
|
inlinenoexcept |
Get the number of bytes received by the client.
Definition at line 85 of file udp_client.h.
|
inlinenoexcept |
Get the number of bytes sent by the client.
Definition at line 83 of file udp_client.h.
|
virtual |
Connect the client (synchronous)
Definition at line 123 of file udp_client.cpp.
|
virtual |
Connect the client using the given DNS resolver (synchronous)
| resolver | - DNS resolver |
Definition at line 173 of file udp_client.cpp.
|
virtual |
Connect the client (asynchronous)
Definition at line 275 of file udp_client.cpp.
|
virtual |
Connect the client using the given DNS resolver (asynchronous)
| resolver | - DNS resolver |
Definition at line 291 of file udp_client.cpp.
|
inlinenoexcept |
Get the number datagrams received by the client.
Definition at line 89 of file udp_client.h.
|
inlinenoexcept |
Get the number datagrams sent by the client.
Definition at line 87 of file udp_client.h.
Disconnect the client (synchronous)
Definition at line 124 of file udp_client.h.
Disconnect the client (asynchronous)
Definition at line 146 of file udp_client.h.
|
inlinenoexcept |
Get the client endpoint.
Definition at line 69 of file udp_client.h.
|
inlinenoexcept |
Get the client Id.
Definition at line 60 of file udp_client.h.
|
inlinenoexcept |
Get the Asio IO service.
Definition at line 65 of file udp_client.h.
|
inlinenoexcept |
Is the client connected?
Definition at line 107 of file udp_client.h.
Join multicast group with a given address (synchronous)
| address | - Multicast group address |
Definition at line 419 of file udp_client.cpp.
Join multicast group with a given address (asynchronous)
| address | - Multicast group address |
Definition at line 447 of file udp_client.cpp.
Leave multicast group with a given address (synchronous)
| address | - Multicast group address |
Definition at line 433 of file udp_client.cpp.
Leave multicast group with a given address (asynchronous)
| address | - Multicast group address |
Definition at line 461 of file udp_client.cpp.
Handle client connected notification.
Definition at line 355 of file udp_client.h.
Handle client disconnected notification.
Definition at line 357 of file udp_client.h.
|
inlineprotectedvirtual |
Handle error notification.
| error | - Error code |
| category | - Error category |
| message | - Error message |
Definition at line 398 of file udp_client.h.
|
inlineprotectedvirtual |
Handle client joined multicast group notification.
| address | - Multicast group address |
Definition at line 363 of file udp_client.h.
|
inlineprotectedvirtual |
Handle client left multicast group notification.
| address | - Multicast group address |
Definition at line 368 of file udp_client.h.
|
inlineprotectedvirtual |
Handle datagram received notification.
Notification is called when another datagram was received from some endpoint.
| endpoint | - Received endpoint |
| buffer | - Received datagram buffer |
| size | - Received datagram buffer size |
Definition at line 379 of file udp_client.h.
|
inlineprotectedvirtual |
Handle datagram sent notification.
Notification is called when a datagram was sent to the server.
This handler could be used to send another datagram to the server for instance when the pending size is zero.
| endpoint | - Endpoint of sent datagram |
| sent | - Size of sent datagram buffer |
Definition at line 390 of file udp_client.h.
|
inlinenoexcept |
Get the option: bind the socket to the multicast UDP server.
Definition at line 96 of file udp_client.h.
|
inlinenoexcept |
Get the option: receive buffer limit.
Definition at line 98 of file udp_client.h.
| size_t CppServer::Asio::UDPClient::option_receive_buffer_size | ( | ) | const |
Get the option: receive buffer size.
Definition at line 97 of file udp_client.cpp.
|
inlinenoexcept |
Get the option: reuse address.
Definition at line 92 of file udp_client.h.
|
inlinenoexcept |
Get the option: reuse port.
Definition at line 94 of file udp_client.h.
|
inlinenoexcept |
Get the option: send buffer limit.
Definition at line 102 of file udp_client.h.
| size_t CppServer::Asio::UDPClient::option_send_buffer_size | ( | ) | const |
Get the option: send buffer size.
Definition at line 104 of file udp_client.cpp.
|
inlinenoexcept |
Get the server port number.
Definition at line 78 of file udp_client.h.
|
virtual |
Receive text from the given endpoint (synchronous)
| endpoint | - Endpoint to receive from |
| size | - Text size to receive |
Definition at line 699 of file udp_client.cpp.
|
virtual |
Receive text from the given endpoint with timeout (synchronous)
| endpoint | - Endpoint to receive from |
| size | - Text size to receive |
| timeout | - Timeout |
Definition at line 766 of file udp_client.cpp.
|
virtual |
Receive datagram from the given endpoint (synchronous)
| endpoint | - Endpoint to receive from |
| buffer | - Datagram buffer to receive |
| size | - Datagram buffer size to receive |
Definition at line 665 of file udp_client.cpp.
|
virtual |
Receive datagram from the given endpoint with timeout (synchronous)
| endpoint | - Endpoint to receive from |
| buffer | - Datagram buffer to receive |
| size | - Datagram buffer size to receive |
| timeout | - Timeout |
Definition at line 706 of file udp_client.cpp.
|
virtual |
Receive datagram from the server (asynchronous)
Definition at line 773 of file udp_client.cpp.
|
virtual |
Reconnect the client (synchronous)
Definition at line 267 of file udp_client.cpp.
|
virtual |
Reconnect the client (asynchronous)
Definition at line 408 of file udp_client.cpp.
|
inlinenoexcept |
Get the scheme name.
Definition at line 76 of file udp_client.h.
|
virtual |
Send datagram to the given endpoint (synchronous)
| endpoint | - Endpoint to send |
| buffer | - Datagram buffer to send |
| size | - Datagram buffer size |
Definition at line 481 of file udp_client.cpp.
|
virtual |
Send datagram to the given endpoint with timeout (synchronous)
| endpoint | - Endpoint to send |
| buffer | - Datagram buffer to send |
| size | - Datagram buffer size |
| timeout | - Timeout |
Definition at line 523 of file udp_client.cpp.
|
inlinevirtual |
Send text to the given endpoint (synchronous)
| endpoint | - Endpoint to send |
| text | - Text to send |
Definition at line 202 of file udp_client.h.
|
inlinevirtual |
Send text to the given endpoint with timeout (synchronous)
| endpoint | - Endpoint to send |
| text | - Text to send |
| timeout | - Timeout |
Definition at line 235 of file udp_client.h.
Send datagram to the connected server (synchronous)
| buffer | - Datagram buffer to send |
| size | - Datagram buffer size |
Definition at line 475 of file udp_client.cpp.
|
virtual |
Send datagram to the connected server with timeout (synchronous)
| buffer | - Datagram buffer to send |
| size | - Datagram buffer size |
| timeout | - Timeout |
Definition at line 517 of file udp_client.cpp.
Send text to the connected server (synchronous)
| text | - Text to send |
Definition at line 187 of file udp_client.h.
|
inlinevirtual |
Send text to the connected server with timeout (synchronous)
| text | - Text to send |
| timeout | - Timeout |
Definition at line 218 of file udp_client.h.
|
virtual |
Send datagram to the given endpoint (asynchronous)
| endpoint | - Endpoint to send |
| buffer | - Datagram buffer to send |
| size | - Datagram buffer size |
Definition at line 593 of file udp_client.cpp.
|
inlinevirtual |
Send text to the given endpoint (asynchronous)
| endpoint | - Endpoint to send |
| text | - Text to send |
Definition at line 264 of file udp_client.h.
Send datagram to the connected server (asynchronous)
| buffer | - Datagram buffer to send |
| size | - Datagram buffer size |
Definition at line 587 of file udp_client.cpp.
Send text to the connected server (asynchronous)
| text | - Text to send |
Definition at line 249 of file udp_client.h.
|
inlinenoexcept |
Get the Asio service.
Definition at line 63 of file udp_client.h.
Setup option: bind the socket to the multicast UDP server.
| enable | - Enable/disable option |
Definition at line 321 of file udp_client.h.
Setup option: receive buffer limit.
The client will be disconnected if the receive buffer limit is met. Default is unlimited.
| limit | - Receive buffer limit |
Definition at line 329 of file udp_client.h.
Setup option: receive buffer size.
This option will setup SO_RCVBUF if the OS support this feature.
| size | - Receive buffer size |
Definition at line 111 of file udp_client.cpp.
Setup option: reuse address.
This option will enable/disable SO_REUSEADDR if the OS support this feature.
| enable | - Enable/disable option |
Definition at line 309 of file udp_client.h.
Setup option: reuse port.
This option will enable/disable SO_REUSEPORT if the OS support this feature.
| enable | - Enable/disable option |
Definition at line 316 of file udp_client.h.
Setup option: send buffer limit.
The client will be disconnected if the send buffer limit is met. Default is unlimited.
| limit | - Send buffer limit |
Definition at line 344 of file udp_client.h.
Setup option: send buffer size.
This option will setup SO_SNDBUF if the OS support this feature.
| size | - Send buffer size |
Definition at line 117 of file udp_client.cpp.
|
inlinenoexcept |
Get the client socket.
Definition at line 71 of file udp_client.h.
|
inlinenoexcept |
Get the Asio service strand for serialized handler execution.
Definition at line 67 of file udp_client.h.