WebSocket
[!NOTE] This document is partially generated by AI.
WebSocket is a transport protocol that provides full-duplex communication channels over a single TCP connection. in yuhaiin, it is used to wrap proxy traffic in HTTP-compliant WebSocket frames.
Network Support
Section titled “Network Support”- TCP: Supported (Stream-based).
- UDP: Not supported natively. WebSocket is designed for reliable stream delivery over TCP.
Client Configuration (Outbound)
Section titled “Client Configuration (Outbound)”When used as an outbound transport layer, the websocket block uses these fields:
Configuration Fields
Section titled “Configuration Fields”host(string): The value for the HTTPHostheader sent during the WebSocket handshake. This must match the domain name the server expects.path(string): The URL path where the WebSocket server is listening (e.g.,/proxy-path).
Server Configuration (Inbound)
Section titled “Server Configuration (Inbound)”yuhaiin can also receive WebSocket connections.
Configuration Fields
Section titled “Configuration Fields”host(string): (Optional) The host header the server will validate against.path(string): The path the server will listen on for incoming WebSocket handshakes.
Example Configuration
Section titled “Example Configuration”Outbound Example
Section titled “Outbound Example”{ "websocket": { "host": "cdn.example.com", "path": "/v2ray-ws" }}Inbound Example
Section titled “Inbound Example”{ "websocket": { "path": "/v2ray-ws" }}Developer Details
Section titled “Developer Details”Compliance
Section titled “Compliance”The implementation is compatible with standard WebSocket clients and servers (e.g., V2Ray, Xray). It performs a standard GET request with Upgrade: websocket and Connection: Upgrade headers.
Implementation
Section titled “Implementation”Found in pkg/net/proxy/websocket. It wraps an underlying net.Conn and provides a stream-oriented interface for higher-level protocols.