Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
core_lib::asio::udp::SimpleUdpSender Class Referencefinal

A simplified UDP sender. More...

#include <SimpleUdpSender.h>

Public Member Functions

 SimpleUdpSender ()=delete
 Default constructor - deleted.
 
 SimpleUdpSender (boost_iocontext_t &ioContext, const defs::connection_t &receiver, eUdpOption sendOption=eUdpOption::broadcast, size_t sendBufferSize=DEFAULT_UDP_BUF_SIZE)
 Initialisation constructor. More...
 
 SimpleUdpSender (const defs::connection_t &receiver, eUdpOption sendOption=eUdpOption::broadcast, size_t sendBufferSize=DEFAULT_UDP_BUF_SIZE)
 Initialisation constructor. More...
 
 SimpleUdpSender (const SimpleUdpSender &)=delete
 Copy constructor - deleted.
 
SimpleUdpSenderoperator= (const SimpleUdpSender &)=delete
 Copy assignment operator - deleted.
 
 SimpleUdpSender (SimpleUdpSender &&)=delete
 Move constructor - deleted.
 
SimpleUdpSenderoperator= (SimpleUdpSender &&)=delete
 Move assignment operator - deleted.
 
 ~SimpleUdpSender ()=default
 Default destructor.
 
defs::connection_t ReceiverConnection () const
 Retrieve receiver connection details. More...
 
bool SendMessage (int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
 Send a header-only message to the receiver. More...
 
bool SendMessage (const defs::char_buffer_t &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
 Send a header plus message buffer to the receiver. More...
 
template<typename T , typename A = serialize::archives::out_port_bin_t>
bool SendMessage (const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
 Send a full message to the server. More...
 
bool SendMessage (const defs::char_buffer_t &message)
 Send a message buffer to the receiver. More...
 

Private Attributes

messages::MessageBuilder m_messageBuilder
 Default message builder object of type core_lib::asio::messages::MessageBuilder.
 
UdpTypedSender< messages::MessageBuilderm_udpTypedSender
 Our actual typed UDP sender object.
 

Detailed Description

A simplified UDP sender.

Constructor & Destructor Documentation

◆ SimpleUdpSender() [1/2]

core_lib::asio::udp::SimpleUdpSender::SimpleUdpSender ( boost_iocontext_t ioContext,
const defs::connection_t receiver,
eUdpOption  sendOption = eUdpOption::broadcast,
size_t  sendBufferSize = DEFAULT_UDP_BUF_SIZE 
)

Initialisation constructor.

Parameters
[in]ioContext- External boost IO context to manage ASIO.
[in]receiver- Connection object describing target receiver's address and port.
[in]sendOption- Socket send option to control the use of broadcasts/unicast.
[in]sendBufferSize- Socket send option to control send buffer size.

Typically use this constructor when managing a bool of threads using an instance of core_lib::asio::IoContextThreadGroup in your application to manage a pool of std::threads. This means you can use a single thread pool and all ASIO operations will be exectued using this thread pool managed by a single IO context. This is the recommended constructor.

◆ SimpleUdpSender() [2/2]

core_lib::asio::udp::SimpleUdpSender::SimpleUdpSender ( const defs::connection_t receiver,
eUdpOption  sendOption = eUdpOption::broadcast,
size_t  sendBufferSize = DEFAULT_UDP_BUF_SIZE 
)
explicit

Initialisation constructor.

Parameters
[in]receiver- Connection object describing target receiver's address and port.
[in]sendOption- Socket send option to control the use of broadcasts/unicast.
[in]sendBufferSize- Socket send option to control send buffer size.

This constructor does not require an external IO context to run instead it creates its own IO context object along with its own thread. For very simple cases this version will be fine but in more performance and resource critical situations the external IO context constructor is recommened.

Member Function Documentation

◆ ReceiverConnection()

auto core_lib::asio::udp::SimpleUdpSender::ReceiverConnection ( ) const

Retrieve receiver connection details.

Returns
- Connection object describing target receiver's address and port.

◆ SendMessage() [1/4]

bool core_lib::asio::udp::SimpleUdpSender::SendMessage ( int32_t  messageId,
const defs::connection_t responseAddress = defs::NULL_CONNECTION 
)

Send a header-only message to the receiver.

Parameters
[in]messageId- Unique message ID to insert into message header.
[in]responseAddress- (Optional) The address and port where the receiver should send the response, the default value will mean the response address will point to this client socket.
Returns
Returns the success state of the send as a boolean.

This method only sends a simple core_lib::asio::defs::MessageHeader object to the server.

◆ SendMessage() [2/4]

bool core_lib::asio::udp::SimpleUdpSender::SendMessage ( const defs::char_buffer_t message,
int32_t  messageId,
const defs::connection_t responseAddress = defs::NULL_CONNECTION 
)

Send a header plus message buffer to the receiver.

Parameters
[in]message- The message buffer.
[in]messageId- Unique message ID to insert into message header.
[in]responseAddress- (Optional) The address and port where the receiver should send the response, the default value will mean the response address will point to this client socket.
Returns
Returns the success state of the send as a boolean.

◆ SendMessage() [3/4]

template<typename T , typename A = serialize::archives::out_port_bin_t>
bool core_lib::asio::udp::SimpleUdpSender::SendMessage ( const T &  message,
int32_t  messageId,
const defs::connection_t responseAddress = defs::NULL_CONNECTION 
)
inline

Send a full message to the server.

Parameters
[in]message- The message of type T to send behind the header serialized to an boost::serialization-compatible archive of type A.
[in]messageId- Unique message ID to insert into message header.
[in]responseAddress- (Optional) The address and port where the receiver should send the response, the default value will mean the response address will point to this client socket.
Returns
Returns the success state of the send as a boolean.

This method uses the a core_lib::asio::defs::MessageHeader object as the header.

◆ SendMessage() [4/4]

bool core_lib::asio::udp::SimpleUdpSender::SendMessage ( const defs::char_buffer_t message)

Send a message buffer to the receiver.

Parameters
[in]message- The message buffer.
Returns
Returns the success state of the send as a boolean.

The documentation for this class was generated from the following files: