QSctpServer Class
QSctpServer 类提供了一个基于 SCTP 的服务器。更多
头文件: | #include <QSctpServer> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake: | QT += network |
继承: | QTcpServer |
- 所有成员(包括继承成员)的列表
- QSctpServer 是网络编程 API 的一部分。
公共函数
QSctpServer(QObject *parent = nullptr) | |
virtual | ~QSctpServer() |
int | maximumChannelCount() const |
QSctpSocket * | nextPendingDatagramConnection() |
void | setMaximumChannelCount(int count) |
重新实现的保护函数
virtual void | incomingConnection(qintptr socketDescriptor) override |
详细说明
SCTP(流控制传输协议)是一种传输层协议,其作用与常用的 TCP 和 UDP 协议类似。与 UDP 一样,SCTP 也是面向消息的,但它能像 TCP 一样通过拥塞控制确保可靠、按顺序传输消息。更多协议详情,请参阅QSctpSocket 文档。
QSctpServer 是QTcpServer 的一个方便子类,它允许你以 TCP 模拟或数据报模式接受传入的 SCTP 套接字连接。
使用 QSctpServer 的最常用方法是构建一个对象,并通过调用setMaximumChannelCount() 设置服务器准备支持的最大通道数。您可以通过在该调用中传递一个负参数来设置 TCP 仿真模式。此外,特殊值 0(默认值)表示使用对等设备的值作为实际通道数。新的传入连接会从服务器套接字描述符中继承该通道数,并根据远程端点设置进行调整。
在 TCP 仿真模式下,接受的客户端使用单个连续字节流进行数据传输,而 QSctpServer 就像一个普通的QTcpServer 。调用nextPendingConnection() 将待处理连接作为已连接的QTcpSocket 接受。函数返回一个指向QAbstractSocket::ConnectedState 中QTcpSocket 的指针,您可以用它与客户端通信。这种模式只能访问 SCTP 协议的基本功能。套接字在系统级通过 IP 传输 SCTP 数据包,并通过QTcpSocket 接口与应用程序交互。
相比之下,数据报模式是面向消息的,可在端点之间同时传输多个数据流。调用nextPendingDatagramConnection() 将待处理的数据报模式连接作为已连接的QSctpSocket 接受。
注: Windows 平台不支持该类。
另请参阅 QTcpServer,QSctpSocket, 和QAbstractSocket 。
成员函数文档
[explicit]
QSctpServer::QSctpServer(QObject *parent = nullptr)
构造一个 QSctpServer 对象。
设置数据报操作模式。parent 参数传递给QObject 的构造函数。
另请参阅 setMaximumChannelCount()、listen() 和setSocketDescriptor()。
[virtual noexcept]
QSctpServer::~QSctpServer()
销毁QSctpServer 对象。如果服务器正在监听连接,则会自动关闭套接字。
另请参阅 close().
[override virtual protected]
void QSctpServer::incomingConnection(qintptr socketDescriptor)
重实现:QTcpServer::incomingConnection(qintptr socketDescriptor)。
int QSctpServer::maximumChannelCount() const
返回接受的套接字所能支持的最大通道数。
值为 0(默认值)表示连接通道数由远程端点设置。
如果QSctpServer 在 TCP 模拟模式下运行,则返回 -1。
另请参阅 setMaximumChannelCount()。
QSctpSocket *QSctpServer::nextPendingDatagramConnection()
以连接QSctpSocket 对象的形式返回下一个待处理的数据报模式连接。
数据报模式连接提供面向消息的多流通信。
套接字是作为服务器的子节点创建的,这意味着当QSctpServer 对象被销毁时,它会被自动删除。为了避免浪费内存,最好还是在使用完该对象后将其明确删除。
如果没有待处理的数据报模式连接,该函数将返回 null。
注意: 返回的QSctpSocket 对象不能在其他线程中使用。如果要使用从其他线程传入的连接,需要重载incomingConnection()。
另请参阅 hasPendingConnections(),nextPendingConnection() 和QSctpSocket 。
void QSctpServer::setMaximumChannelCount(int count)
将服务器在数据报模式下准备支持的最大通道数设置为count 。如果count 为 0,则使用端点最大通道数值。负count 设置 TCP 模拟模式。
只有当QSctpServer 处于未连接状态时才调用此方法。
另请参阅 maximumChannelCount() 和QSctpSocket 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.