![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QSctpSocket class provides an SCTP socket. More...
#include <qsctpsocket.h>
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) |
The QSctpSocket class provides an SCTP socket.
\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
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().
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.
Definition at line 17 of file qsctpsocket.h.
|
explicit |
Creates a QSctpSocket object in state UnconnectedState
.
Sets the datagram operation mode. The parent argument is passed to QObject's constructor.
Definition at line 309 of file qsctpsocket.cpp.
|
virtual |
Destroys the socket, closing the connection if necessary.
Definition at line 323 of file qsctpsocket.cpp.
|
override |
\reimp
Definition at line 358 of file qsctpsocket.cpp.
|
overridevirtual |
bool QSctpSocket::isInDatagramMode | ( | ) | const |
Returns true
if the socket is running in datagram mode.
Definition at line 422 of file qsctpsocket.cpp.
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.
Definition at line 412 of file qsctpsocket.cpp.
\reimp
Definition at line 332 of file qsctpsocket.cpp.
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}.
Definition at line 440 of file qsctpsocket.cpp.
\reimp
Definition at line 345 of file qsctpsocket.cpp.
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.
Definition at line 387 of file qsctpsocket.cpp.
bool QSctpSocket::writeDatagram | ( | const QNetworkDatagram & | datagram | ) |
Writes a datagram to the buffer of the current write channel.
Returns true on success; otherwise returns false.
Definition at line 476 of file qsctpsocket.cpp.