Skip to content

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.

  • TCP: Supported (Stream-based).
  • UDP: Not supported natively. WebSocket is designed for reliable stream delivery over TCP.

When used as an outbound transport layer, the websocket block uses these fields:

  • host (string): The value for the HTTP Host header 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).

yuhaiin can also receive WebSocket connections.

  • host (string): (Optional) The host header the server will validate against.
  • path (string): The path the server will listen on for incoming WebSocket handshakes.
{
"websocket": {
"host": "cdn.example.com",
"path": "/v2ray-ws"
}
}
{
"websocket": {
"path": "/v2ray-ws"
}
}

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.

Found in pkg/net/proxy/websocket. It wraps an underlying net.Conn and provides a stream-oriented interface for higher-level protocols.