|
Core Library
1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
|
A generic bi-directional TCP client. More...
#include <TcpTypedClient.h>
Public Member Functions | |
| TcpTypedClient ()=delete | |
| Default constructor - deleted. | |
| TcpTypedClient (boost_iocontext_t &ioContext, const defs::connection_t &server, size_t minAmountToRead, const defs::check_bytes_left_to_read_t &checkBytesLeftToRead, const defs::message_received_handler_t &messageReceivedHandler, const MsgBldr &messageBuilder, eSendOption sendOption=eSendOption::nagleOn, size_t maxAllowedUnsentAsyncMessages=MAX_UNSENT_ASYNC_MSG_COUNT) | |
| Initialisation constructor. More... | |
| TcpTypedClient (const defs::connection_t &server, size_t minAmountToRead, const defs::check_bytes_left_to_read_t &checkBytesLeftToRead, const defs::message_received_handler_t &messageReceivedHandler, const MsgBldr &messageBuilder, eSendOption sendOption=eSendOption::nagleOn, size_t maxAllowedUnsentAsyncMessages=MAX_UNSENT_ASYNC_MSG_COUNT) | |
| Initialisation constructor. More... | |
| ~TcpTypedClient ()=default | |
| Default destructor. | |
| TcpTypedClient (const TcpTypedClient &)=delete | |
| Copy constructor - deleted. | |
| TcpTypedClient & | operator= (const TcpTypedClient &)=delete |
| Copy assignment operator - deleted. | |
| TcpTypedClient (TcpTypedClient &&)=delete | |
| Move constructor - deleted. | |
| TcpTypedClient & | operator= (TcpTypedClient &&)=delete |
| Move assignment operator - deleted. | |
| defs::connection_t | ServerConnection () const |
| Retrieve server connection details. More... | |
| bool | Connected () const |
| Check if the client is connected to the server. More... | |
| defs::connection_t | GetClientDetailsForServer () |
| Retrieve this client's connection details. More... | |
| void | CloseConnection () |
| Manually close the connection. More... | |
| bool | SendMessageToServerAsync (int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) |
| Send a header-only message to the server asynchronously. More... | |
| bool | SendMessageToServerSync (int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) |
| Send a header-only message to the server synchronously. More... | |
| bool | SendMessageToServerAsync (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 server asynchronously. More... | |
| bool | SendMessageToServerSync (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 server synchronously. More... | |
| template<typename T , typename A = serialize::archives::out_port_bin_t> | |
| bool | SendMessageToServerAsync (const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) |
| Send a full message to the server asynchronously. More... | |
| template<typename T , typename A = serialize::archives::out_port_bin_t> | |
| bool | SendMessageToServerSync (const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) |
| Send a full message to the server synchronously. More... | |
| bool | SendMessageToServerAsync (const defs::char_buffer_t &message) |
| Send a message buffer to the server asynchronously. More... | |
| bool | SendMessageToServerSync (const defs::char_buffer_t &message) |
| Send a message buffer to the server synchronously. More... | |
| size_t | NumberOfUnsentAsyncMessages () const |
| Get number of unsent async messages. More... | |
Private Attributes | |
| std::mutex | m_sendMutex |
| Send message mutex. | |
| const MsgBldr & | m_messageBuilder |
| Referece to our message builder object. | |
| TcpClient | m_tcpClient |
| General purpose TCP client object. | |
A generic bi-directional TCP client.
The template argument defines a message builder object that must have an interface compatible with that of the class core_lib::asio::messages::MessageBuilder.
This class forms the underpinnings of the SimpleTcpClient class.
This is also the class to be used when the user wants to specify their own message builder type and message header type.
|
inline |
Initialisation constructor.
| [in] | ioContext | - External boost IO context to manage ASIO. |
| [in] | server | - Connection object describing target server's address and port. |
| [in] | minAmountToRead | - Minimum amount of data to read on each receive, typical size of header block. |
| [in] | checkBytesLeftToRead | - Function object capable of decoding the message and computing how many bytes are left until a complete message. |
| [in] | messageReceivedHandler | - Function object cpable of handling a received message and dispatching it accordingly. |
| [in] | messageBuilder | - A const reference to our persistent message builder object of type MsgBldr. |
| [in] | sendOption | - Socket send option to control the use of the Nagle algorithm. |
| [in] | maxAllowedUnsentAsyncMessages | - Maximum allowed number of unsent async messages. |
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 executed using this thread pool managed by a single IO context. This is the recommended constructor.
|
inline |
Initialisation constructor.
| [in] | server | - Connection object describing target server's address and port. |
| [in] | minAmountToRead | - Minimum amount of data to read on each receive, typical size of header block. |
| [in] | checkBytesLeftToRead | - Function object capable of decoding the message and computing how many bytes are left until a complete message. |
| [in] | messageReceivedHandler | - Function object capable of handling a received message and dispatching it accordingly. |
| [in] | messageBuilder | - A message builder object of type MsgBldr. |
| [in] | sendOption | - Socket send option to control the use of the Nagle algorithm. |
| [in] | maxAllowedUnsentAsyncMessages | - Maximum allowed number of unsent async messages. |
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 recommended.
|
inline |
Manually close the connection.
Note that this object uses RAII so will close the connection when destroyed.
|
inline |
Check if the client is connected to the server.
|
inline |
Retrieve this client's connection details.
Throws xUnknownConnectionError is remoteEnd is not valid.
|
inline |
Get number of unsent async messages.
|
inline |
Send a header-only message to the server asynchronously.
| [in] | messageId | - Unique message ID to insert into message header. |
| [in] | responseAddress | - (Optional) The address and port where the server should send the response, the default value will mean the response address will point to this client socket. |
|
inline |
Send a header plus message buffer to the server asynchronously.
| [in] | message | - Message buffer. |
| [in] | messageId | - Unique message ID to insert into message header. |
| [in] | responseAddress | - (Optional) The address and port where the server should send the response, the default value will mean the response address will point to this client socket. |
|
inline |
Send a full message to the server asynchronously.
| [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 server should send the response, the default value will mean the response address will point to this client socket. |
|
inline |
Send a message buffer to the server asynchronously.
| [in] | message | - Message buffer. |
|
inline |
Send a header-only message to the server synchronously.
| [in] | messageId | - Unique message ID to insert into message header. |
| [in] | responseAddress | - (Optional) The address and port where the server should send the response, the default value will mean the response address will point to this client socket. |
|
inline |
Send a header plus message buffer to the server synchronously.
| [in] | message | - Message buffer. |
| [in] | messageId | - Unique message ID to insert into message header. |
| [in] | responseAddress | - (Optional) The address and port where the server should send the response, the default value will mean the response address will point to this client socket. |
|
inline |
Send a full message to the server synchronously.
| [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 server should send the response, the default value will mean the response address will point to this client socket. |
|
inline |
Send a message buffer to the server synchronously.
| [in] | message | - Message buffer. |
|
inline |
Retrieve server connection details.