Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QSctpSocket Class Reference

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

#include <qsctpsocket.h>

Inheritance diagram for QSctpSocket:
Collaboration diagram for QSctpSocket:

Public Member Functions

 QSctpSocket (QObject *parent=nullptr)
 Creates a QSctpSocket object in state UnconnectedState.
virtual ~QSctpSocket ()
 Destroys the socket, closing the connection if necessary.
void close () override
 \reimp
void disconnectFromHost () override
 \reimp
void setMaximumChannelCount (int count)
 Sets the maximum number of channels that the application is prepared to support in datagram mode, to count.
int maximumChannelCount () const
 Returns the maximum number of channels that QSctpSocket is able to support.
bool isInDatagramMode () const
 Returns true if the socket is running in datagram mode.
QNetworkDatagram readDatagram ()
 Reads a datagram from the buffer of the current read channel, and returns it as a QNetworkDatagram object, along with the sender's host address and port.
bool writeDatagram (const QNetworkDatagram &datagram)
 Writes a datagram to the buffer of the current write channel.
Public Member Functions inherited from QTcpSocket
 QTcpSocket (QObject *parent=nullptr)
 Creates a QTcpSocket object in state UnconnectedState.
virtual ~QTcpSocket ()
 Destroys the socket, closing the connection if necessary.
Public Member Functions inherited from QAbstractSocket
 QAbstractSocket (SocketType socketType, QObject *parent)
 Creates a new abstract socket of type socketType.
virtual ~QAbstractSocket ()
 Destroys the socket.
virtual void resume ()
PauseModes pauseMode () const
void setPauseMode (PauseModes pauseMode)
virtual bool bind (const QHostAddress &address, quint16 port=0, BindMode mode=DefaultForPlatform)
bool bind (QHostAddress::SpecialAddress addr, quint16 port=0, BindMode mode=DefaultForPlatform)
bool bind (quint16 port=0, BindMode mode=DefaultForPlatform)
virtual void connectToHost (const QString &hostName, quint16 port, OpenMode mode=ReadWrite, NetworkLayerProtocol protocol=AnyIPProtocol)
 Attempts to make a connection to hostName on the given port.
void connectToHost (const QHostAddress &address, quint16 port, OpenMode mode=ReadWrite)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Attempts to make a connection to address on port port.
bool isValid () const
 Returns true if the socket is valid and ready for use; otherwise returns false.
qint64 bytesAvailable () const override
 Returns the number of incoming bytes that are waiting to be read.
qint64 bytesToWrite () const override
 Returns the number of bytes that are waiting to be written.
quint16 localPort () const
 Returns the host port number (in native byte order) of the local socket if available; otherwise returns 0.
QHostAddress localAddress () const
 Returns the host address of the local socket if available; otherwise returns QHostAddress::Null.
quint16 peerPort () const
 Returns the port of the connected peer if the socket is in ConnectedState; otherwise returns 0.
QHostAddress peerAddress () const
 Returns the address of the connected peer if the socket is in ConnectedState; otherwise returns QHostAddress::Null.
QString peerName () const
 Returns the name of the peer as specified by connectToHost(), or an empty QString if connectToHost() has not been called.
qint64 readBufferSize () const
 Returns the size of the internal read buffer.
virtual void setReadBufferSize (qint64 size)
 Sets the size of QAbstractSocket's internal read buffer to be size bytes.
void abort ()
 Aborts the current connection and resets the socket.
virtual qintptr socketDescriptor () const
 Returns the native socket descriptor of the QAbstractSocket object if this is available; otherwise returns -1.
virtual bool setSocketDescriptor (qintptr socketDescriptor, SocketState state=ConnectedState, OpenMode openMode=ReadWrite)
 Initializes QAbstractSocket with the native socket descriptor socketDescriptor.
virtual void setSocketOption (QAbstractSocket::SocketOption option, const QVariant &value)
virtual QVariant socketOption (QAbstractSocket::SocketOption option)
SocketType socketType () const
 Returns the socket type (TCP, UDP, or other).
SocketState state () const
 Returns the state of the socket.
SocketError error () const
 Returns the type of error that last occurred.
void close () override
 Closes the I/O device for the socket and calls disconnectFromHost() to close the socket's connection.
bool isSequential () const override
 \reimp
bool flush ()
 This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking.
virtual bool waitForConnected (int msecs=30000)
 Waits until the socket is connected, up to msecs milliseconds.
bool waitForReadyRead (int msecs=30000) override
 This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} signal has been emitted.
bool waitForBytesWritten (int msecs=30000) override
 \reimp
virtual bool waitForDisconnected (int msecs=30000)
 Waits until the socket has disconnected, up to msecs milliseconds.
void setProxy (const QNetworkProxy &networkProxy)
QNetworkProxy proxy () const
QString protocolTag () const
void setProtocolTag (const QString &tag)

Protected Member Functions

qint64 readData (char *data, qint64 maxlen) override
 \reimp
qint64 readLineData (char *data, qint64 maxlen) override
 \reimp
Protected Member Functions inherited from QTcpSocket
 QTcpSocket (QTcpSocketPrivate &dd, QObject *parent=nullptr)
 QTcpSocket (QAbstractSocket::SocketType socketType, QTcpSocketPrivate &dd, QObject *parent=nullptr)
Protected Member Functions inherited from QAbstractSocket
qint64 readData (char *data, qint64 maxlen) override
 \reimp
qint64 readLineData (char *data, qint64 maxlen) override
 \reimp
qint64 skipData (qint64 maxSize) override
 \reimp
qint64 writeData (const char *data, qint64 len) override
 \reimp
void setSocketState (SocketState state)
 Sets the state of the socket to state.
void setSocketError (SocketError socketError)
 Sets the type of error that last occurred to socketError.
void setLocalPort (quint16 port)
void setLocalAddress (const QHostAddress &address)
void setPeerPort (quint16 port)
void setPeerAddress (const QHostAddress &address)
void setPeerName (const QString &name)
 QAbstractSocket (SocketType socketType, QAbstractSocketPrivate &dd, QObject *parent=nullptr)

Additional Inherited Members

Public Types inherited from QAbstractSocket
enum  SocketType { TcpSocket , UdpSocket , SctpSocket , UnknownSocketType = -1 }
 This enum describes the transport layer protocol. More...
enum  SocketError {
  ConnectionRefusedError , RemoteHostClosedError , HostNotFoundError , SocketAccessError ,
  SocketResourceError , SocketTimeoutError , DatagramTooLargeError , NetworkError ,
  AddressInUseError , SocketAddressNotAvailableError , UnsupportedSocketOperationError , UnfinishedSocketOperationError ,
  ProxyAuthenticationRequiredError , SslHandshakeFailedError , ProxyConnectionRefusedError , ProxyConnectionClosedError ,
  ProxyConnectionTimeoutError , ProxyNotFoundError , ProxyProtocolError , OperationError ,
  SslInternalError , SslInvalidUserDataError , TemporaryError , UnknownSocketError = -1
}
 This enum describes the socket errors that can occur. More...
enum  SocketState {
  UnconnectedState , HostLookupState , ConnectingState , ConnectedState ,
  BoundState , ListeningState , ClosingState
}
 This enum describes the different states in which a socket can be. More...
enum  SocketOption {
  LowDelayOption , KeepAliveOption , MulticastTtlOption , MulticastLoopbackOption ,
  TypeOfServiceOption , SendBufferSizeSocketOption , ReceiveBufferSizeSocketOption , PathMtuSocketOption
}
enum  BindFlag { DefaultForPlatform = 0x0 , ShareAddress = 0x1 , DontShareAddress = 0x2 , ReuseAddressHint = 0x4 }
enum  PauseMode { PauseNever = 0x0 , PauseOnSslErrors = 0x1 }
Public Types inherited from QtPrivate::QAbstractSocketConstants
using NetworkLayerProtocol = QHostAddress::NetworkLayerProtocol
Signals inherited from QAbstractSocket
void hostFound ()
 This signal is emitted after connectToHost() has been called and the host lookup has succeeded.
void connected ()
 This signal is emitted after connectToHost() has been called and a connection has been successfully established.
void disconnected ()
 This signal is emitted when the socket has been disconnected.
void stateChanged (QAbstractSocket::SocketState)
 This signal is emitted whenever QAbstractSocket's state changes.
void errorOccurred (QAbstractSocket::SocketError)
void proxyAuthenticationRequired (const QNetworkProxy &proxy, QAuthenticator *authenticator)
Static Public Attributes inherited from QtPrivate::QAbstractSocketConstants
static constexpr auto IPv4Protocol = QHostAddress::IPv4Protocol
static constexpr auto IPv6Protocol = QHostAddress::IPv6Protocol
static constexpr auto AnyIPProtocol = QHostAddress::AnyIPProtocol
static constexpr auto UnknownNetworkLayerProtocol = QHostAddress::UnknownNetworkLayerProtocol

Detailed Description

The QSctpSocket class provides an SCTP socket.

Since
5.8

\inmodule QtNetwork

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:

\list

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

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().

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 class is not supported on the Windows platform.
See also
QSctpServer, QTcpSocket, QAbstractSocket

Definition at line 17 of file qsctpsocket.h.

Constructor & Destructor Documentation

◆ QSctpSocket()

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

Creates a QSctpSocket object in state UnconnectedState.

Sets the datagram operation mode. The parent argument is passed to QObject's constructor.

See also
socketType(), setMaximumChannelCount()

Definition at line 309 of file qsctpsocket.cpp.

◆ ~QSctpSocket()

QSctpSocket::~QSctpSocket ( )
virtual

Destroys the socket, closing the connection if necessary.

See also
close()

Definition at line 323 of file qsctpsocket.cpp.

Member Function Documentation

◆ close()

void QSctpSocket::close ( )
override

\reimp

Definition at line 358 of file qsctpsocket.cpp.

◆ disconnectFromHost()

void QSctpSocket::disconnectFromHost ( )
overridevirtual

\reimp

Reimplemented from QAbstractSocket.

Definition at line 366 of file qsctpsocket.cpp.

◆ isInDatagramMode()

bool QSctpSocket::isInDatagramMode ( ) const

Returns true if the socket is running in datagram mode.

See also
setMaximumChannelCount()

Definition at line 422 of file qsctpsocket.cpp.

◆ maximumChannelCount()

int QSctpSocket::maximumChannelCount ( ) const

Returns the maximum number of channels that QSctpSocket is able to support.

A value of 0 (the default) means that the number of connection channels would be set by the remote endpoint.

Returns -1 if QSctpSocket is running in continuous byte stream mode.

See also
setMaximumChannelCount(), readChannelCount(), writeChannelCount()

Definition at line 412 of file qsctpsocket.cpp.

◆ readData()

qint64 QSctpSocket::readData ( char * data,
qint64 maxlen )
overrideprotected

\reimp

Definition at line 332 of file qsctpsocket.cpp.

◆ readDatagram()

QNetworkDatagram QSctpSocket::readDatagram ( )

Reads a datagram from the buffer of the current read channel, and returns it as a QNetworkDatagram object, along with the sender's host address and port.

If possible, this function will also try to determine the datagram's destination address, port, and the number of hop counts at reception time.

On failure, returns a QNetworkDatagram that reports \l {QNetworkDatagram::isValid()}{not valid}.

See also
writeDatagram(), isInDatagramMode(), currentReadChannel()

Definition at line 440 of file qsctpsocket.cpp.

◆ readLineData()

qint64 QSctpSocket::readLineData ( char * data,
qint64 maxlen )
overrideprotected

\reimp

Definition at line 345 of file qsctpsocket.cpp.

◆ setMaximumChannelCount()

void QSctpSocket::setMaximumChannelCount ( int count)

Sets the maximum number of channels that the application is prepared to support in datagram mode, to count.

If count is 0, endpoint's value for maximum number of channels is used. Negative count sets a continuous byte stream mode.

Call this method only when QSctpSocket is in UnconnectedState.

See also
maximumChannelCount(), readChannelCount(), writeChannelCount()

Definition at line 387 of file qsctpsocket.cpp.

◆ writeDatagram()

bool QSctpSocket::writeDatagram ( const QNetworkDatagram & datagram)

Writes a datagram to the buffer of the current write channel.

Returns true on success; otherwise returns false.

See also
readDatagram(), isInDatagramMode(), currentWriteChannel()

Definition at line 476 of file qsctpsocket.cpp.


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