JSONRPC2 v2.0.0 JSONRPC2.Servers.TCP View Source

A server for JSON-RPC 2.0 using a line-based TCP transport.

Link to this section Summary

Functions

Returns a supervisor child spec for the given handler on port with opts.

Start a server with the given handler on port with opts.

Stop the server with name.

Link to this section Functions

Link to this function

child_spec(handler, port, opts \\ [])

View Source

Specs

child_spec(module(), :inet.port_number(), Keyword.t()) :: {:ok, pid()}

Returns a supervisor child spec for the given handler on port with opts.

Allows you to embed a server directly in your app's supervision tree, rather than letting Ranch handle it.

See start_listener/3 for available options.

Link to this function

start_listener(handler, port, opts \\ [])

View Source

Specs

start_listener(module(), :inet.port_number(), Keyword.t()) :: {:ok, pid()}

Start a server with the given handler on port with opts.

Available options:

  • name - a unique name that can be used to stop the server later. Defaults to the value of handler.
  • num_acceptors - number of acceptor processes to start. Defaults to 100.
  • transport - ranch transport to use. Defaults to :ranch_tcp.
  • transport_opts - ranch transport options. For :ranch_tcp, see here.
  • timeout - disconnect after this amount of milliseconds without a packet from a client. Defaults to 1 hour.
  • line_packet - by default, packets consist of a 4 byte header containing an unsigned integer in big-endian byte order specifying the number of bytes in the packet, followed by that number of bytes (equivalent to the erlang inet packet type 4). If set to true, packets will instead be terminated by line-endings, for compatibility with older implementations.

Specs

stop(atom()) :: :ok | {:error, :not_found}

Stop the server with name.