websocket

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected          = errors.New("socket not connected")
	ErrDecodeABI             = errors.New("failed to decode ABI")
	ErrExpectedABI           = errors.New("expected abi message")
	ErrExpectedBinaryMessage = errors.New("expected binary message")
)

Functions

func IsCloseError added in v0.2.6

func IsCloseError(err error, codes ...int) bool

Types

type Client

type Client struct {

	// True if we care about the abi.
	FetchABI bool

	// Pointer to the ABI
	ABI *chain.Abi
	// contains filtered or unexported fields
}

Client is a low-level SHIP websocket client.

func NewClient

func NewClient(options ...Option) *Client

Create a new client

func (*Client) Close

func (c *Client) Close() error

Close the socket on the client side.

NOTE: This method closes the underlying network connection without sending any close message.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, url string) error

Connect connects to a ship node

Url must be of the form schema://host[:port] and schema should be "ws" or "wss"

The provided Context must be non-nil. If the context expires or is canceled before the connection is complete, an error is returned.

func (*Client) IsOpen

func (c *Client) IsOpen() bool

Returns true if the websocket connection is open. false otherwise.

func (*Client) Read

func (c *Client) Read() (ship.Result, error)

Read a result message from the websocket.

This function will block until atleast one message is read or an error occurred.

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) error

Shutdown closes the connection gracefully by sending a Close handshake. This function will block until a close message is received from the server an error occure or context is canceled.

Note: Shutdown will not read anything from the stream. it assumes there is some other thread that reads and process the close message returned from the server

func (*Client) Write

func (c *Client) Write(req ship.Request) error

Write a request to the ship server.

func (*Client) WriteClose

func (c *Client) WriteClose(code int, reason string) error

Write a websocket close message to the server.

type Option

type Option func(*Client)

func WithFetchABI

func WithFetchABI(value bool) Option

func WithReadBufferSize added in v0.2.8

func WithReadBufferSize(value int) Option

Jump to

Keyboard shortcuts

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