jsonrpcws

package
v0.0.0-...-931966b Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: EPL-2.0 Imports: 3 Imported by: 4

Documentation

Overview

Package jsonrpcws provides implementation of jsonrpc.NativeConn based on websocket.

The example:

Client:

	conn, err := jsonrpcws.Dial("ws://host:port/path", token123456798)
	if err != nil {
     	panic(err)
     }
	tunnel := jsonrpc.NewTunnel(conn, jsonrpc.DefaultRouter)
	tunnel.Go()
	tunnel.SayHello()

Server:

	conn, err := jsonrpcws.Upgrade(w, r)
	if err != nil {
     	panic(err)
     }
	tunnel := jsonrpc.NewTunnel(conn, jsonrpc.DefaultRouter)
	tunnel.Go()
	tunnel.SayHello()

Index

Constants

This section is empty.

Variables

View Source
var (
	// default upgrader that is used for upgrading http connection to WebSocket
	// may be changed by client if custom settings are needed
	DefaultUpgrader = &websocket.Upgrader{
		ReadBufferSize:  1024,
		WriteBufferSize: 1024,
		CheckOrigin: func(r *http.Request) bool {
			return true
		},
	}

	// default dialer that is used for WebSocket connection establishing
	// may be changed by client if custom settings are needed
	DefaultDialer = websocket.DefaultDialer
)

Functions

This section is empty.

Types

type NativeConnAdapter

type NativeConnAdapter struct {

	// RequestURI is http.Request URI which is set on connection Upgrade.
	RequestURI string
	// contains filtered or unexported fields
}

NativeConnAdapter adapts WebSocket connection to jsonrpc.NativeConn.

func Dial

func Dial(url string, token string) (*NativeConnAdapter, error)

Dial establishes a new client WebSocket connection. If argument 'token' is empty authentication won't be used, otherwise authorization token will be added.

func Upgrade

Upgrade upgrades http connection to WebSocket connection.

func (*NativeConnAdapter) Close

func (adapter *NativeConnAdapter) Close() error

Close closes this connection.

func (*NativeConnAdapter) Next

func (adapter *NativeConnAdapter) Next() ([]byte, error)

Next reads next text message from the WebSocket connection.

func (*NativeConnAdapter) Write

func (adapter *NativeConnAdapter) Write(data []byte) error

Write writes text message to the WebSocket connection.

Jump to

Keyboard shortcuts

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