QSctpSocket Class

The QSctpSocket class provides an SCTP socket. More...

Header: #include <QSctpSocket>
qmake: QT += network
Since: Qt 5.8
Inherits: QTcpSocket

This class was introduced in Qt 5.8.

Detailed Description

SCTP (Stream Control Transmission Protocol) is a transport layer protocol serving in a similar role as the popular protocols TCP and UDP. Like UDP, SCTP is message-oriented, but it ensures reliable, in-sequence transport of messages with congestion control like TCP.

SCTP is connection-oriented protocol, which provides the complete simultaneous transmission of multiple data streams between endpoints. This multi-streaming allows data to be delivered by independent channels, so that if there is data loss in one stream, delivery will not be affected for the other streams.

Being message-oriented, SCTP transports a sequence of messages, rather than transporting an unbroken stream of bytes as does TCP. Like in UDP, in SCTP a sender sends a message in one operation, and that exact message is passed to the receiving application process in one operation. But unlike UDP, the delivery is guaranteed.

It also supports multi-homing, meaning that a connected endpoint can have alternate IP addresses associated with it in order to route around network failure or changing conditions.

QSctpSocket is a convenience subclass of QTcpSocket that allows you to emulate TCP data stream over SCTP or establish an SCTP connection for reliable datagram service.

QSctpSocket can operate in one of two possible modes:

  • Continuous byte stream (TCP emulation).
  • Multi-streamed datagram mode.

To set a continuous byte stream mode, instantiate QSctpSocket and call setMaximumChannelCount() with a negative value. This gives the ability to use QSctpSocket as a regular buffered QTcpSocket. You can call connectToHost() to initiate connection with endpoint, write() to transmit and read() to receive data from the peer, but you cannot distinguish message boundaries.

By default, QSctpSocket operates in datagram mode. Before connecting, call setMaximumChannelCount() to set the maximum number of channels that the application is prepared to support. This number is a parameter negotiated with the remote endpoint and its value can be bounded by the operating system. The default value of 0 indicates to use the peer's value. If both endpoints have default values, then number of connection channels is system-dependent. After establishing a connection, you can fetch the actual number of channels by calling readChannelCount() and writeChannelCount().

 QSctpSocket *socket = new QSctpSocket(this);

 socket->setMaxChannelCount(16);
 socket->connectToHost(QHostAddress::LocalHost, 1973);

 if (socket->waitForConnected(1000)) {
     int inputChannels = socket->readChannelCount();
     int outputChannels = socket->writeChannelCount();

     ....
 }

In datagram mode, QSctpSocket performs the buffering of datagrams independently for each channel. You can queue a datagram to the buffer of the current channel by calling writeDatagram() and read a pending datagram by calling readDatagram() respectively.

Using the standard QIODevice functions read(), readLine(), write(), etc. is allowed in datagram mode with the same limitations as in continuous byte stream mode.

Note: This feature is not supported on the Windows platform.

See also QSctpServer, QTcpSocket, and QAbstractSocket.