client

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JsonRPCVersion Defines the version of the JSON-RPC protocol being used.
	JsonRPCVersion = "2.0"

	// Default timeout for receiving requests from the server, in milliseconds.
	DefaultTimeout = 3000

	// The default buffer size for a subscription.
	DefaultSubscriptionBufferSize = 10000

	// The default message buffer size for reading messages from the connection.
	DefaultMessageBufferSize = 512
)

Variables

View Source
var (
	ClientIsDisconnectedError  = errors.New("Client is disconnected and closed")
	TimeoutError               = errors.New("Timeout Error")
	InvalidResponseIDError     = errors.New("Invalid response ID")
	InvalidResponseResultError = errors.New("Invalid response result")
)

Functions

This section is empty.

Types

type RPCClient

type RPCClient struct {
	// contains filtered or unexported fields
}

RPCClient RPC Client

func NewRPCClient

func NewRPCClient(config RPCClientConfig) (*RPCClient, error)

NewRPCClient creates a new instance of RPCClient with the provided configuration. It establishes a WebSocket connection to the RPC server and starts a background receiving loop. Returns an error if the connection cannot be established.

func (*RPCClient) Call

func (client *RPCClient) Call(method string, params any) (json.RawMessage, error)

Call sends a synchronous RPC call to the server with the specified method and parameters. It waits for and returns the response result, or an error if the call fails.

func (*RPCClient) Close

func (client *RPCClient) Close()

Close gracefully shuts down the RPC client by closing the WebSocket connection, stopping the background receiving loop, and cleaning up all resources. It ensures the client can only be closed once using atomic operations.

func (*RPCClient) Subscribe

func (client *RPCClient) Subscribe(method string, params any) (*util.Subscription, error)

Subscribe sends a subscription request to the server and returns a Subscription object. The subscription can be used to receive notifications from the server for the specified method.

func (*RPCClient) Unsubscribe

func (client *RPCClient) Unsubscribe(method string, subID message.SubscriptionID) error

Unsubscribe sends an unsubscription request to the server to cancel the specified subscription. It removes the subscription from the local subscription manager upon successful completion.

type RPCClientConfig

type RPCClientConfig struct {
	Timeout                int    // Timeout for receiving requests from the server, in milliseconds.
	Addr                   string // Address of the RPC server.
	SubscriptionBufferSize int    // The buffer size for a subscription.
	MessageBufferSize      int    // The buffer size for reading messages from the connection.
	ChannelBufferSize      int    // The buffer size for response channels in MessageDispatcher.
}

RPCClientConfig Holds the configuration settings for the RPC client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL