hackney_ws (hackney v2.0.0)
View Sourcegen_statem process for WebSocket connections.
This module implements a state machine for WebSocket connections, handling HTTP upgrade handshake and WebSocket frame exchange.
States: - idle: Process started, not connected - upgrading: HTTP upgrade in progress - connected: WebSocket ready for messages - closing: Close handshake in progress - closed: Connection terminated
Summary
Functions
Close the WebSocket connection gracefully.
Initiate WebSocket connection. Blocks until upgrade completes.
Assign a new controlling process.
Return the address and port for the other end of connection.
Receive a WebSocket frame (passive mode only).
Send a WebSocket frame. Frame types: {text, Data}, {binary, Data}, ping, {ping, Data}, pong, {pong, Data}, close, {close, Code, Reason}
Set socket options. Supported: [{active, true|false|once}]
Get the local address and port of the socket.
Start a WebSocket connection process. Options
Types
Functions
-spec close(pid()) -> ok.
Close the WebSocket connection gracefully.
Initiate WebSocket connection. Blocks until upgrade completes.
Assign a new controlling process.
-spec peername(pid()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, term()}.
Return the address and port for the other end of connection.
Receive a WebSocket frame (passive mode only).
Send a WebSocket frame. Frame types: {text, Data}, {binary, Data}, ping, {ping, Data}, pong, {pong, Data}, close, {close, Code, Reason}
Set socket options. Supported: [{active, true|false|once}]
-spec sockname(pid()) -> {ok, {inet:ip_address(), inet:port_number()}} | {error, term()}.
Get the local address and port of the socket.
Start a WebSocket connection process. Options:
- host: Target host (string or binary)
- port: Target port (integer)
- transport: hackney_tcp or hackney_ssl
- path: WebSocket path (binary, default "/")
- connect_timeout: Connection timeout (default 8000ms)
- recv_timeout: Receive timeout (default infinity)
- connect_options: Options passed to transport connect
- ssl_options: Additional SSL options
- active: false | true | once (default false)
- headers: Extra headers for upgrade request
- protocols: Sec-WebSocket-Protocol values