- Qt 6.10
- Qt Network
- C++ Classes
- QSslServer
- Qt 6.10.2 Reference Documentation

# QSslServer Class

Implements an encrypted, secure TCP server over TLS. More...

Header: | `#include <QSslServer>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Network)` `target_link_libraries(mytarget PRIVATE Qt6::Network)`
qmake: | `QT += network`
Since: | Qt 6.4
Inherits: | QTcpServer

- List of all members, including inherited members
- QSslServer is part of Network Programming API.

## Public Functions

| QSslServer(QObject *parent = nullptr)
virtual | ~QSslServer() override
int | handshakeTimeout() const
void | setHandshakeTimeout(int timeout)
void | setSslConfiguration(const QSslConfiguration &sslConfiguration)
QSslConfiguration | sslConfiguration() const

## Reimplemented Protected Functions

virtual void | incomingConnection(qintptr socket) override

## Detailed Description

Class to use in place of QTcpServer to implement TCP server using Transport Layer Security (TLS).

To configure the secure handshake settings, use the applicable setter functions on a QSslConfiguration object, and then use it as an argument to the setSslConfiguration() function. All following incoming connections handled will use these settings.

To start listening to incoming connections use the listen() function inherited from QTcpServer. Other settings can be configured by using the setter functions inherited from the QTcpServer class.

Connect to the signals of this class to respond to the incoming connection attempts. They are the same as the signals on QSslSocket, but also passes a pointer to the socket in question.

When responding to the pendingConnectionAvailable() signal, use the nextPendingConnection() function to fetch the next incoming connection and take it out of the pending connection queue. The QSslSocket is a child of the QSslServer and will be deleted when the QSslServer is deleted. It is still a good idea to destroy the object explicitly when you are done with it, to avoid wasting memory.

See also QTcpServer, QSslConfiguration, and QSslSocket.

## Member Function Documentation

### `[explicit]` QSslServer::QSslServer(QObject *parent = nullptr)

Constructs a new QSslServer with the given parent.

### `[override virtual noexcept]` QSslServer::~QSslServer()

Destroys the QSslServer.

All open connections are closed.

### int QSslServer::handshakeTimeout() const

Returns the currently configured handshake timeout.

See also setHandshakeTimeout().

### `[override virtual protected]` void QSslServer::incomingConnection(qintptr socket)

Reimplements: QTcpServer::incomingConnection(qintptr socketDescriptor).

Called when a new connection is established.

Converts socket to a QSslSocket.

### void QSslServer::setHandshakeTimeout(int timeout)

Sets the timeout to use for all incoming handshakes, in milliseconds.

This is relevant in the scenario where a client, whether malicious or accidental, connects to the server but makes no attempt at communicating or initiating a handshake. QSslServer will then automatically end the connection after timeout milliseconds have elapsed.

By default the timeout is 5000 milliseconds (5 seconds).

Note: The underlying TLS framework may have their own timeout logic now or in the future, this function does not affect that.

Note: The timeout passed to this function will only apply to new connections. If a client is already connected it will use the timeout which was set when it connected.

See also handshakeTimeout().

### void QSslServer::setSslConfiguration(const QSslConfiguration &sslConfiguration)

Sets the sslConfiguration to use for all following incoming connections.

This must be called before listen() to ensure that the desired configuration was in use during all handshakes.

See also sslConfiguration() and QSslSocket::setSslConfiguration().

### QSslConfiguration QSslServer::sslConfiguration() const

Returns the current ssl configuration.

See also setSslConfiguration().