JS8Call-Improved master
Loading...
Searching...
No Matches
TCPClient Class Reference

Simple TCP client wrapper. More...

#include <TCPClient.h>

Inheritance diagram for TCPClient:
Collaboration diagram for TCPClient:

Public Types

using port_type = quint16

Public Slots

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.

Public Member Functions

 TCPClient (QObject *parent=nullptr)
 Construct a new TCPClient::TCPClient object.

Detailed Description

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.

Constructor & Destructor Documentation

◆ TCPClient()

TCPClient::TCPClient ( QObject * parent = nullptr)
explicit

Construct a new TCPClient::TCPClient object.

Parameters
parent

Member Function Documentation

◆ 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
hostThe hostname or IP address to connect to.
portThe port number to connect to.
msecsThe timeout in milliseconds to wait for the connection.
Returns
true if connected successfully, false otherwise.
Here is the caller graph for this function:

◆ 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
hostDestination hostname or IP.
portDestination port.
messageByte payload to send.
crlfWhen true append CRLF to the message.
msecsConnection/send timeout in milliseconds.
Returns
true on success, false on failure.
Parameters
hostThe hostname or IP address to send the message to.
portThe port number to send the message to.
messageThe message data to send.
crlfWhether to append CRLF to the message.
msecsThe timeout in milliseconds to wait for the connection.
Returns
true if the message was sent successfully, false otherwise.
Here is the call graph for this function:

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