client

package
v0.1.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents an instance of one of the servers clients

func NewClient

func NewClient(
	serverAddr string,
	hooks Hooks,
	defaultTimeout time.Duration,
	warningLogWriter io.Writer,
	errorLogWriter io.Writer,
) Client

NewClient creates a new disconnected client instance.

func (*Client) Close

func (clt *Client) Close()

Close gracefully closes the connection. Does nothing if the client isn't connected

func (*Client) CloseSession

func (clt *Client) CloseSession() error

CloseSession closes the currently active session and synchronizes the closure to the server if connected. If the client is not connected then the synchronization is skipped. Does nothing if there's no active session

func (*Client) Connect

func (clt *Client) Connect() (err error)

Connect connects the client to the configured server and returns an error in case of a connection failure. Automatically tries to restore the previous session

func (*Client) IsConnected

func (clt *Client) IsConnected() bool

IsConnected returns true if the client is connected to the server, otherwise false is returned

func (*Client) PendingRequests

func (clt *Client) PendingRequests() int

PendingRequests returns the number of currently pending requests

func (*Client) Request

func (clt *Client) Request(
	name string,
	payload webwire.Payload,
) (webwire.Payload, *webwire.Error)

Request sends a request containing the given payload to the server and asynchronously returns the servers response blocking the calling goroutine. Returns an error if the request failed for some reason

func (*Client) RestoreSession

func (clt *Client) RestoreSession(sessionKey []byte) error

RestoreSession tries to restore the previously opened session. Fails if a session is currently already active

func (*Client) Session

func (clt *Client) Session() webwire.Session

Session returns information about the current session

func (*Client) Signal

func (clt *Client) Signal(name string, payload webwire.Payload) error

Signal sends a signal containing the given payload to the server

func (*Client) TimedRequest

func (clt *Client) TimedRequest(
	name string,
	payload webwire.Payload,
	timeout time.Duration,
) (webwire.Payload, *webwire.Error)

TimedRequest sends a request containing the given payload to the server and asynchronously returns the servers reply blocking the calling goroutine. Returns an error if the given timeout was exceeded awaiting the response or another failure occurred

type Hooks

type Hooks struct {
	// OnServerSignal is an optional callback.
	// It's invoked when the webwire client receives a signal from the server
	OnServerSignal func(payload webwire.Payload)

	// OnSessionCreated is an optional callback.
	// It's invoked when the webwire client receives a new session
	OnSessionCreated func(*webwire.Session)

	// OnSessionClosed is an optional callback.
	// It's invoked when the clients session was closed
	// either by the server or by himself
	OnSessionClosed func()
}

Hooks represents all callback hook functions

func (*Hooks) SetDefaults

func (hooks *Hooks) SetDefaults()

SetDefaults sets undefined required hooks

Jump to

Keyboard shortcuts

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