安全的 WebSocket 回显服务器

一个通过安全 WebSocket(wss)响应客户端的简单服务器。

“安全 WebSocket 回显服务器”示例演示了如何使用 `QWebSocketServer ` 类在安全套接字 (wss) 上实现一个简单的回显服务器。此示例需要支持 TLS 才能运行。它会向客户端进行身份验证,验证成功后,可接收来自客户端的消息并予以响应。 为便于说明,其响应内容仅为收到的消息的副本。

该服务器配置了自签名证书和密钥。除非连接该服务器的客户端被配置为信任该证书(如“安全 WebSocket 回显客户端”所示),否则客户端将拒绝该服务器。

安全的 WebSocket 回显 HTML 客户端

本示例中包含一个基于 HTML 的客户端。但它仅在以下两种情况下才能正常工作:所用浏览器支持上述证书,或者该浏览器会忽略针对 localhost 地址的 TLS 错误。

示例项目 @ code.qt.io

另请参阅 《安全 WebSocket 回显客户端》和《WebSocket 回显服务器》。

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