# server-trans **Repository Path**: lvlinhai/server-trans ## Basic Information - **Project Name**: server-trans - **Description**: rs - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-24 - **Last Updated**: 2025-07-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Server-Trans: WebSocket 请求转发系统 一个基于WebSocket的请求转发系统,包含两个组件: 1. **服务器端** - 部署在公网服务器上,接收HTTP请求并通过WebSocket转发给客户端 2. **客户端** - 部署在内网或公司电脑上,接收WebSocket消息并转发到目标服务器 ## 工作原理 1. 客户端通过WebSocket连接到服务器 2. 外部请求(如手机)发送HTTP请求到服务器 3. 服务器将请求通过WebSocket发送给已连接的客户端 4. 客户端向目标服务器发送HTTP请求并获取响应 5. 客户端通过WebSocket将响应发回给服务器 6. 服务器将响应返回给原始请求者 ## 编译 ```bash cargo build --release ``` ## 运行服务器 ```bash # 默认监听在127.0.0.1:8080 ./target/release/server # 自定义配置 ./target/release/server -H 0.0.0.0 --port 8080 ``` ## 运行客户端 ```bash # 默认连接到ws://127.0.0.1:8080/ws并转发到http://example.com ./target/release/client # 自定义配置 ./target/release/client --server-url ws://公网服务器IP:8080/ws --target-url http://本地或内网服务地址 ``` ## 特点 - 客户端主动连接服务器,适合穿越NAT网络 - 支持所有HTTP方法、请求头和请求体 - 自动重连机制,确保连接稳定 - 心跳检测,保持连接活跃 - 可扩展,支持多客户端连接(可实现负载均衡) ## 注意事项 1. 确保服务器防火墙开放WebSocket端口(默认8080) 2. 客户端需要能够访问外网(至少能够访问服务器) 3. 若长时间无请求,连接会保持活跃(通过心跳机制)