A simple bi-directional TCP client, which uses the class MessageHeader as the message header type.
More...
|
|
| SimpleTcpClient ()=delete |
| | Default constructor - deleted.
|
| |
| | SimpleTcpClient (boost_iocontext_t &ioContext, const defs::connection_t &server, const defs::default_message_dispatcher_t &messageDispatcher, eSendOption sendOption=eSendOption::nagleOn, size_t maxAllowedUnsentAsyncMessages=MAX_UNSENT_ASYNC_MSG_COUNT, size_t memPoolMsgCount=0) |
| | Initialisation constructor. More...
|
| |
| | SimpleTcpClient (const defs::connection_t &server, const defs::default_message_dispatcher_t &messageDispatcher, eSendOption sendOption=eSendOption::nagleOn, size_t maxAllowedUnsentAsyncMessages=MAX_UNSENT_ASYNC_MSG_COUNT, size_t memPoolMsgCount=0) |
| | Initialisation constructor. More...
|
| |
|
| ~SimpleTcpClient ()=default |
| | Default destructor.
|
| |
|
| SimpleTcpClient (const SimpleTcpClient &)=delete |
| | Copy constructor - deleted.
|
| |
|
SimpleTcpClient & | operator= (const SimpleTcpClient &)=delete |
| | Copy assignment operator - deleted.
|
| |
|
| SimpleTcpClient (SimpleTcpClient &&)=delete |
| | Move constructor - deleted.
|
| |
|
SimpleTcpClient & | operator= (SimpleTcpClient &&)=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...
|
| |
A simple bi-directional TCP client, which uses the class MessageHeader as the message header type.
Initialisation constructor.
- Parameters
-
| [in] | ioContext | - External boost IO context to manage ASIO. |
| [in] | server | - Connection object describing target server's address and port. |
| [in] | messageDispatcher | - Callback to use to dispatch received messages. |
| [in] | sendOption | - Socket send option to control the use of the Nagle algorithm. |
| [in] | maxAllowedUnsentAsyncMessages | - Maximum allowed number of unsent async messages. |
| [in] | memPoolMsgCount | - Number of messages (per client) in pool for received message handling, defaults to 0, which implies no pool used. |
Typically use this constructor when managing a bool of threads using an instance of core_lib::asioIoServoceThreadGroup 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.
NOTE: When the message pool feature is used then all messages passed to the the registered dispatcher are managed by the internal pool. Care must be taken in the dispatcher to process the messages as quickly as possibly so the pool doesn't fill and start overwriting older messages. If the messages need to be kept then it is the dispatchers job to make a suitable copy of the received message.
Initialisation constructor.
- Parameters
-
| [in] | server | - Connection object describing target server's address and port. |
| [in] | messageDispatcher | - Callback to use to dispatch received messages. |
| [in] | sendOption | - Socket send option to control the use of the Nagle algorithm. |
| [in] | maxAllowedUnsentAsyncMessages | - Maximum allowed number of unsent async messages. |
| [in] | memPoolMsgCount | - Number of messages (per client) in pool for received message handling, defaults to 0, which implies no pool used. |
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 recommend.
NOTE: When the message pool feature is used then all messages passed to the the registered dispatcher are managed by the internal pool. Care must be taken in the dispatcher to process the messages as quickly as possibly so the pool doesn't fill and start overwriting older messages. If the messages need to be kept then it is the dispatchers job to make a suitable copy of the received message.