WebSocket 回显客户端
演示如何编写一个简单的 WebSocket 客户端应用程序。
该回显客户端演示了如何使用WebSocketAPI 向服务器发送消息,并处理服务器返回的任何响应——在本例中,仅简单地输出响应内容。
该客户端默认会与监听本地端口 1234 的服务器建立 WebSocket 连接。当连接尝试成功后,客户端将向服务器发送一条消息,并输出服务器发送的任何响应。随后,客户端会关闭连接。

为了便于说明,我们使用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.