简单 WebSocket 聊天

使用 WebSocket 协议的简易聊天应用程序。

该应用程序展示了如何使用QWebSocketQWebSocketServer 类通过 WebSocket 协议创建简约的聊天应用程序。该示例是一个服务器,允许多个客户端连接到它来发送和接收消息。

默认情况下,它在 localhost 1234 端口监听。它会跟踪所有连接到它的客户端,每次其中一个客户端向服务器发送信息时,该信息就会转发给所有其他客户端。当客户端断开连接时,它就会从客户端列表中删除。

简单的 WebSocket 聊天 HTML 客户端

还有一个 HTML 客户端,用于连接服务器和断开服务器连接、查询连接情况、发送消息和查看其他客户端发送的所有消息。

示例项目 @ code.qt.io

© 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.