KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
TcpServer Class Referenceabstract

Abstract TCP server supporting both plain-text and TLS/SSL connections. More...

#include <tcpserver.h>

+ Inheritance diagram for TcpServer:
+ Collaboration diagram for TcpServer:

Public Member Functions

 TcpServer (const QHostAddress &serverAddress, int serverPort)
 Construct a plain-text TCP server.
 
 TcpServer (const QHostAddress &serverAddress, int serverPort, const QSslKey &privateKey, const QSslCertificate &localCertificate, const QSslCertificate &caCert, bool verifyPeer=false)
 Construct an SSL/TLS TCP server with a single CA certificate.
 
 TcpServer (const QHostAddress &serverAddress, int serverPort, const QSslKey &privateKey, const QSslCertificate &localCertificate, const QList< QSslCertificate > &caCerts, bool verifyPeer=false)
 Construct an SSL/TLS TCP server with a list of CA certificates.
 
virtual ~TcpServer ()
 Destructor — stops the server and cleans up all client connections.
 
bool start ()
 Start the server and begin accepting connections.
 
void stop ()
 Stop the server and close all active client connections.
 
QSslKey privateKey () const
 Return the server's private key (SSL mode only).
 
QSslCertificate localCertificate () const
 Return the server's local certificate (SSL mode only).
 
QList< QSslCertificate > caCerts () const
 Return the list of CA certificates (SSL mode only).
 
bool verifyPeer () const
 Return whether peer certificate verification is enabled.
 
QDateTime startTime () const
 Return the time the server was started.
 
- Public Member Functions inherited from LoggingBaseClass
 LoggingBaseClass (const Log::LogCategory &category=Log::LogCategory())
 Construct with an optional log category.
 
 LoggingBaseClass (const QString &category)
 Construct with a category name string.
 
Log::LogCategory logCategory () const
 Return the base log category.
 

Protected Member Functions

virtual TcpServerClientObjectcreateClient (TcpServer *server, qintptr fd)=0
 Factory method called for each incoming connection.
 
virtual void incomingConnection (qintptr handle) override
 Handle a new incoming connection by delegating to createClient().
 
- Protected Member Functions inherited from LoggingBaseClass
Log::LogCategory LVL0 () const
 Return the base (level 0) log category.
 
Log::LogCategory LVL1 () const
 Return the level-1 sub-category.
 
Log::LogCategory LVL2 () const
 Return the level-2 sub-category.
 
Log::LogCategory LVL3 () const
 Return the level-3 sub-category.
 
void logText (const char *file, int lineNumber, Log::LogLevel level, const QString &text) const
 Write a text message to the system logger using the base category.
 
void logText (const char *file, int lineNumber, Log::LogLevel level, const Log::LogCategory &category, const QString &text) const
 Write a text message to the system logger using an explicit category.
 
void logHex (const char *file, int lineNumber, Log::LogLevel level, const QByteArray &data, const QString &tag=QString()) const
 Write a hex dump to the system logger.
 
void logHex (const char *file, int lineNumber, Log::LogLevel level, const Log::LogCategory &category, const QByteArray &data, const QString &tag=QString()) const
 Write a hex dump to the system logger using an explicit category.
 
void addLogConsumer (LogConsumer *consumer)
 Register an external log consumer to receive entries from this class.
 
void removeLogConsumer (LogConsumer *consumer)
 Remove a previously added log consumer.
 

Detailed Description

Abstract TCP server supporting both plain-text and TLS/SSL connections.

Subclass TcpServer and implement createClient() to construct the appropriate TcpServerClientObject for each incoming connection. The server runs its listen loop in a dedicated QThread; call start() and stop() to control it.

Definition at line 25 of file tcpserver.h.

Constructor & Destructor Documentation

◆ TcpServer() [1/3]

TcpServer::TcpServer ( const QHostAddress &  serverAddress,
int  serverPort 
)

Construct a plain-text TCP server.

Parameters
serverAddressAddress to listen on
serverPortPort to listen on

◆ TcpServer() [2/3]

TcpServer::TcpServer ( const QHostAddress &  serverAddress,
int  serverPort,
const QSslKey &  privateKey,
const QSslCertificate &  localCertificate,
const QSslCertificate &  caCert,
bool  verifyPeer = false 
)

Construct an SSL/TLS TCP server with a single CA certificate.

Parameters
serverAddressAddress to listen on
serverPortPort to listen on
privateKeyServer private key
localCertificateServer certificate
caCertCA certificate for client verification
verifyPeerWhether to require client certificate verification

◆ TcpServer() [3/3]

TcpServer::TcpServer ( const QHostAddress &  serverAddress,
int  serverPort,
const QSslKey &  privateKey,
const QSslCertificate &  localCertificate,
const QList< QSslCertificate > &  caCerts,
bool  verifyPeer = false 
)

Construct an SSL/TLS TCP server with a list of CA certificates.

Parameters
serverAddressAddress to listen on
serverPortPort to listen on
privateKeyServer private key
localCertificateServer certificate
caCertsList of CA certificates
verifyPeerWhether to require client certificate verification

Member Function Documentation

◆ caCerts()

QList< QSslCertificate > TcpServer::caCerts ( ) const
inline

Return the list of CA certificates (SSL mode only).

Returns
List of CA certificates

Definition at line 79 of file tcpserver.h.

◆ createClient()

virtual TcpServerClientObject * TcpServer::createClient ( TcpServer server,
qintptr  fd 
)
protectedpure virtual

Factory method called for each incoming connection.

Parameters
serverPointer to this server
fdNative socket file descriptor for the new connection
Returns
Newly allocated TcpServerClientObject to manage the connection

◆ incomingConnection()

virtual void TcpServer::incomingConnection ( qintptr  handle)
overrideprotectedvirtual

Handle a new incoming connection by delegating to createClient().

Parameters
handleNative socket descriptor for the incoming connection

◆ localCertificate()

QSslCertificate TcpServer::localCertificate ( ) const
inline

Return the server's local certificate (SSL mode only).

Returns
Server certificate

Definition at line 76 of file tcpserver.h.

◆ privateKey()

QSslKey TcpServer::privateKey ( ) const
inline

Return the server's private key (SSL mode only).

Returns
Server private key

Definition at line 73 of file tcpserver.h.

◆ start()

bool TcpServer::start ( )

Start the server and begin accepting connections.

Returns
true if the server started successfully

◆ startTime()

QDateTime TcpServer::startTime ( ) const
inline

Return the time the server was started.

Returns
QDateTime of the last successful start()

Definition at line 88 of file tcpserver.h.

◆ verifyPeer()

bool TcpServer::verifyPeer ( ) const
inline

Return whether peer certificate verification is enabled.

Returns
true if peer verification is enabled

Definition at line 82 of file tcpserver.h.


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