ws_h1_tcp_server (ws v0.1.1)

View Source

Reference HTTP/1.1 WebSocket server over gen_tcp.

A minimal acceptor-loop + upgrade driver built on top of the library's own helpers. Intended both as a runnable example and as the server-side driver for the end-to-end test suite. Embedders with a full HTTP stack will not need it.

{ok, Pid} = ws_h1_tcp_server:start_link(#{ port => 8080, handler => my_handler, handler_opts => #{} }), {ok, ActualPort} = ws_h1_tcp_server:port(Pid), ... ok = ws_h1_tcp_server:stop(Pid).

Options: port :: inet:port_number(). Default 0 (OS-picked). ip :: inet:ip_address() | any. Default any. handler :: module(). Required. handler_opts :: term(). Default #{}. subprotocols :: [binary()]. Required subprotocols; the server picks the first matching one from the client offer. tls :: [ssl:tls_server_option()]. If present, the server terminates TLS on the connection (wss). parser_opts :: map(). Passed through to ws:accept/6. timeout :: timeout(). Handshake read timeout (default 15000 ms).

Summary

Types

opts/0

-type opts() ::
          #{port => inet:port_number(),
            ip => inet:ip_address() | any,
            handler := module(),
            handler_opts => term(),
            subprotocols => [binary()],
            tls => [term()],
            parser_opts => map(),
            timeout => timeout(),
            max_handshake_size => pos_integer()}.

Functions

port(Pid)

-spec port(pid()) -> {ok, inet:port_number()} | {error, term()}.

start_link(Opts)

-spec start_link(opts()) -> {ok, pid()} | {error, term()}.

stop(Pid)

-spec stop(pid()) -> ok.