Simple TCP client wrapper.
More...
#include <TCPClient.h>
|
|
using | port_type = quint16 |
|
| Q_SLOT bool | ensureConnected (QString host, port_type port, int msecs=5000) |
| | Ensure a TCP connection to host:port within msecs milliseconds.
|
| Q_SLOT bool | sendNetworkMessage (QString host, port_type port, QByteArray const &message, bool crlf=true, int msecs=5000) |
| | Send a short network message to host:port.
|
Simple TCP client wrapper.
The API is intentionally small: ensureConnected() will try to establish a connection within a timeout and sendNetworkMessage() sends a message optionally terminated with CR/LF.
◆ TCPClient()
| TCPClient::TCPClient |
( |
QObject * | parent = nullptr | ) |
|
|
explicit |
◆ ensureConnected
| bool TCPClient::ensureConnected |
( |
QString | host, |
|
|
port_type | port, |
|
|
int | msecs = 5000 ) |
|
slot |
Ensure a TCP connection to host:port within msecs milliseconds.
Ensures that the TCP client is connected to the specified host and port.
- Returns
- true when connected, false on timeout or error.
- Parameters
-
| host | The hostname or IP address to connect to. |
| port | The port number to connect to. |
| msecs | The timeout in milliseconds to wait for the connection. |
- Returns
- true if connected successfully, false otherwise.
◆ sendNetworkMessage
| bool TCPClient::sendNetworkMessage |
( |
QString | host, |
|
|
port_type | port, |
|
|
QByteArray const & | message, |
|
|
bool | crlf = true, |
|
|
int | msecs = 5000 ) |
|
slot |
Send a short network message to host:port.
Sends a network message to the specified host and port.
- Parameters
-
| host | Destination hostname or IP. |
| port | Destination port. |
| message | Byte payload to send. |
| crlf | When true append CRLF to the message. |
| msecs | Connection/send timeout in milliseconds. |
- Returns
- true on success, false on failure.
- Parameters
-
| host | The hostname or IP address to send the message to. |
| port | The port number to send the message to. |
| message | The message data to send. |
| crlf | Whether to append CRLF to the message. |
| msecs | The timeout in milliseconds to wait for the connection. |
- Returns
- true if the message was sent successfully, false otherwise.
The documentation for this class was generated from the following files: