JSONRPC2 v0.3.0 JSONRPC2.Clients.TCP

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

Summary

Functions

Call the given method with params using the client pool named name

Asynchronously call the given method with params using the client pool named name

Send a notification with the given method and params using the client pool named name

Receive the response for a previous cast/3 which returned a request_id

Start a client pool named name, connected to host at port

Stop the client pool with name name

Types

host ::
  binary |
  :inet.socket_address |
  :inet.hostname
request_id :: any

Functions

call(name, method, params, string_id \\ false)

Specs

call(atom, JSONRPC2.method, JSONRPC2.params, boolean) ::
  {:ok, any} |
  {:error, any}

Call the given method with params using the client pool named name.

For compatibility with pathological implementations, you can optionally pass true for the string_id parameter to force the request ID to be a string.

cast(name, method, params, string_id \\ false)

Specs

cast(atom, JSONRPC2.method, JSONRPC2.params, boolean) ::
  {:ok, request_id} |
  {:error, :backlog_full}

Asynchronously call the given method with params using the client pool named name.

Use receive_response/1 with the request_id to get the response.

For compatibility with pathological implementations, you can optionally pass true for the string_id parameter to force the request ID to be a string.

notify(name, method, params)

Specs

notify(atom, JSONRPC2.method, JSONRPC2.params) ::
  {:ok, request_id} |
  {:error, :backlog_full}

Send a notification with the given method and params using the client pool named name.

This function returns a request_id, but it should not be used with receive_response/1.

receive_response(request_id)

Specs

receive_response(request_id) ::
  {:ok, any} |
  {:error, any}

Receive the response for a previous cast/3 which returned a request_id.

start(host, port, name, client_opts \\ [], pool_opts \\ [])

Specs

start(host, :inet.port_number, atom, Keyword.t, Keyword.t) :: :ok

Start a client pool named name, connected to host at port.

You can optionally pass client_opts, detailed here, as well as pool_opts, detailed here.

stop(name)

Specs

stop(atom) ::
  :ok |
  {:error, :shackle_not_started | :pool_not_started}

Stop the client pool with name name.