QSctpServer Class

QSctpServer 提供了一个基于 QSCTP 协议的服务器. More...

头文件: #include <QSctpServer>
qmake: QT += network
开始支持版本: Qt 5.8
基类: QTcpServer

公有函数

QSctpServer(QObject *parent = nullptr)
virtual ~QSctpServer()
int maximumChannelCount() const
QSctpSocket *nextPendingDatagramConnection()
void setMaximumChannelCount(int count)

重新实现的受保护函数

virtual void incomingConnection(qintptr socketDescriptor)
  • 2 个受保护的函数继承自 QTcpServer
  • 9 个受保护的函数继承自 QObject

其他继承的成员

详细描述

SCTP (Stream Control Transmission Protocol) 是一种传输层协议, 其作用与流行的协议 TCP 和 UDP 类似. 像 UDP 一样, SCTP 也是面向消息的, 但是它可以通过与 TCP 类似的拥塞控制来确保消息的可靠性, 让消息按顺序传输. 详见 QSctpSocket.

QSctpServer 是 QTcpServer 的便捷子类, 它允许你以 TCP 模拟或数据报模式接受传入的 SCTP 套接字连接.

QSctpServer 最常见的用法是构造一个 QSctpServer 对象, 并调用 setMaximumChannelCount() 函数设置该服务器准备支持的最大通道数. 你可以在调用 setMaximumChannelCount()函数时传入一个负值, 这样便可以让服务端在 TCP 模拟模式下运行. 另外, 如果在 setMaximumChannelCount 函数调用时传入0(0也是默认值), 这会指定服务端使用对等端设置的最大通道数目. 新的传入连接从服务器套接字描述符继承此数字,并根据远程端点设置对其进行调整.

在 TCP 模拟模式下, 服务端允许客户端使用一条连续的字节流来进行数据传输. 此时 QSctpSocket 的操作模式与普通的 QTcpServer 类似. 你可以调用 nextPendingConnection() 函数将一个待处理的连接作为一个已连接的 QTcpSocket 套字节来接受. 你可以使用该 QTcpSocket 套接字与客户端进行通信. 此模式仅能使用基本的 SCTP 协议功能. 套接字在系统层面通过 IP 传输 SCTP 数据包, 并通过 QTcpSocket 接口与应用程序进行交互.

与 TCP 模拟模式相反, 数据报模式是面向消息的, 并且在端点之间提供了多个数据流的完全同时传输. 你可以调用 nextPendingDatagramConnection() 函数将待处理的数据报模式的连接作为一个已连接的 QSctpSocket 套接字接受.

注意: WIndows系统不支持该特性.

另见 QTcpServer, QSctpSocket, QAbstractSocket.

Member Function Documentation

QSctpServer::QSctpServer(QObject *parent = nullptr)

Constructs a QSctpServer object.

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

See also setMaximumChannelCount(), listen(), and setSocketDescriptor().

[virtual] QSctpServer::~QSctpServer()

Destroys the QSctpServer object. If the server is listening for connections, the socket is automatically closed.

See also close().

[override virtual protected] void QSctpServer::incomingConnection(qintptr socketDescriptor)

Reimplements: QTcpServer::incomingConnection(qintptr socketDescriptor).

int QSctpServer::maximumChannelCount() const

Returns the maximum number of channels that the accepted sockets are 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 QSctpServer running in TCP emulation mode.

See also setMaximumChannelCount().

QSctpSocket *QSctpServer::nextPendingDatagramConnection()

Returns the next pending datagram-mode connection as a connected QSctpSocket object.

Datagram-mode connection provides a message-oriented, multi-stream communication.

The socket is created as a child of the server, which means that it is automatically deleted when the QSctpServer object is destroyed. It is still a good idea to delete the object explicitly when you are done with it, to avoid wasting memory.

This function returns null if there are no pending datagram-mode connections.

Note: The returned QSctpSocket object cannot be used from another thread. If you want to use an incoming connection from another thread, you need to override incomingConnection().

See also hasPendingConnections(), nextPendingConnection(), and QSctpSocket.

void QSctpServer::setMaximumChannelCount(int count)

Sets the maximum number of channels that the server is prepared to support in datagram mode, to count. If count is 0, endpoint maximum number of channels value would be used. Negative count sets a TCP emulation mode.

Call this method only when QSctpServer is in UnconnectedState.

See also maximumChannelCount() and QSctpSocket.