You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WebSocket代理数据接收异常问题求助

WebSocket转TCP服务的数据接收异常排查

服务器配置

Server A(172.16.2.5)

运行Python应用,创建WebSocket连接至Server B并周期性发送消息:

from time import sleep
from websocket import create_connection
ws = create_connection("ws://172.16.2.6:80/")
while True:
    print("Sending...")
    ws.send("Hello world")
    print("Sent")
    sleep(5)

Server B(172.16.2.6)

运行websockify工具,将WebSocket连接转发至Server C的TCP服务,启动命令:

./run -v 80 172.16.2.7:33333

Server C(172.16.2.7)

运行Python TCP服务接收Server B转发的消息:

import socket, time
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind('', 33333)
    s.listen()
    conn, addr = s.accept()
    with conn:
        print("Connected by", addr)
        while True:
            data = conn.recv(11)
            print("Received: %s" % data)
            time.sleep(5)

运行现象

Server A输出(无报错)

Sending...
Sent
Sending...
Sent

Server B的websockify输出(Server A启动后立即打印)

172.16.2.5: new handler Process
172.16.2.5 - - [07/Jun/2024 15:40:36] "GET / HTTP/1.1" 101 -
172.16.2.5 - - [07/Jun/2024 15:40:36] 172.16.2.5: Plain non-SSL (ws://) WebSocket connection
172.16.2.5 - - [07/Jun/2024 15:40:36] connecting to: 172.16.2.7:33333

Server C输出(Server A启动后立即打印)

Connected by ('172.16.2.6', 32906)

异常问题

  1. Server C调用conn.recv(11)时永久阻塞,直到停止Server A应用后,才开始每5秒输出Received:消息;
  2. Server C无法接收有效数据,仅持续输出Received: b'',预期应为每5秒输出Received: Hello world。

内容的提问来源于stack exchange,提问作者pacoverflow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:38:17