Documentation
¶
Index ¶
Constants ¶
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 ¶
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 ¶
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 ¶
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.