class

JsonRpc::Client

Inherits Reference / Object

Client class for JSON-RPC. See one of its sub-classes for implementations.

The client offers a built-in flood-protection for received messages. Note that these are counted towards all messages, and thus include responses to made remote invocations from our end.

By default, the flood-protection allows for 6000 messages per minute, or about 100 messages per second. You can change these values through #flood_time_span and #flood_messages.

Constructors

Instance methods

async_call

If true, all locally invoked methods will be run in their own fiber.

Source
async_call=(async_call : Bool)

If true, all locally invoked methods will be run in their own fiber.

Source
call(result_type, method : String, params = nil)

Calls a remote method with optional params, returning a result_type.

Error behaviour

On success the result of the invocation is returned. If however the remote signals an error through the "error" field (per JSON-RPC), it will be re-raised locally as RemoteCallError.

See #call? for a non-raising version.

Source
call?(result_type, method : String, params = nil)

Calls a remote method, returning the result. On error, a RemoteCallError is returned. Otherwise, the nilable result is returned.

Source
close

Closes the connection.

Source
connection_lost
Source
fatal_local_error
Source
fatal_remote_error
Source
flood_messages

Count of max messages in #flood_time_span, after which the flood protection is triggered.

Set to nil to disable the flood-protection.

Source
flood_messages=(flood_messages : Int32 | Nil)

Count of max messages in #flood_time_span, after which the flood protection is triggered.

Set to nil to disable the flood-protection.

Source
flood_protection_triggered
Source
flood_time_span

Time span in which a max count of #flood_messages messages can be received before triggering the flood protection.

Source
flood_time_span=(flood_time_span : Time::Span)

Time span in which a max count of #flood_messages messages can be received before triggering the flood protection.

Source
handler

Handler which is called whenever a call is received from the remote end. The default implementation rejects every call immediately.

See also Handler#call.

Source
handler=(handler : Handler)

Handler which is called whenever a call is received from the remote end. The default implementation rejects every call immediately.

See also Handler#call.

Source
invoke_from_remote(request : Request, raw : String) : Nil

Called by Client implementations to invoke a local method.

Source
messages_received

Total count of messages received.

Source
messages_sent

Total count of messages sent.

Source
notification
Source
notify(method : String, params = nil)

Sends a notification to method with params to the remote end.

Source
notify_raw(message : String)

Sends a notification to the remote end, that is already serialized. Useful to send a notification to many clients in bulk.

Use Request#to_json for easy construction of a message.

Source
recv_message(id)

Called to receive a message.

Source
remote_address

Returns the remote address for display/logging purposes

Source
running?

If the client is currently running, accepting messages, and hopefully also still connected.

Source
send_message(id, message_data : String)

Called to send message_data identified by id.

Source
send_response(response : Response)

Used by DelayedResponse to send a response.

Source

Nested types