websocket

package
v0.0.0-...-c640e2a Latest Latest
Warning

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

Go to latest
Published: May 17, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package websocket provides a simple package that implements a websocket protocol transmission for the octo.TranmissionProtocol interface. Which allows a uniform response cycle with a websocket based connection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseSocketAttr

type BaseSocketAttr struct {
	Authenticate       bool
	MessageCompression bool
	SkipCORS           bool
	Headers            http.Header
	OriginValidator    RequestOriginValidator
	Pub                *server.Pub
}

BaseSocketAttr defines a attribute struct for defining options for the WebsocketServer struct.

type BaseSocketServer

type BaseSocketServer struct {
	MessageCompression bool
	Attr               BaseSocketAttr
	// contains filtered or unexported fields
}

BaseSocketServer defines the struct which implements the core functionality of the websocket request handler and implements the http.Handler interface.

func NewBaseSocketServer

func NewBaseSocketServer(instruments octo.Instrumentation, attr BaseSocketAttr, info octo.Contact, credentials octo.Credentials, system server.System) *BaseSocketServer

NewBaseSocketServer returns a new instance of a BaseSocketServer.

func (*BaseSocketServer) Clients

func (s *BaseSocketServer) Clients() []*Client

Clients returns the client list of the BaseSocketServer object.

func (*BaseSocketServer) Close

func (s *BaseSocketServer) Close() error

Close ends the websocket connection and ensures all requests are finished.

func (*BaseSocketServer) Contact

func (s *BaseSocketServer) Contact() octo.Contact

Contact returns the giving info struct for the giving socket server.

func (*BaseSocketServer) ServeHTTP

func (s *BaseSocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP defines a method to serve and handle websocket requests.

type Client

type Client struct {
	*websocket.Conn

	Request *http.Request
	// contains filtered or unexported fields
}

Client defines a struct to defines a websocket client connection for managing each request client.

func (*Client) Close

func (c *Client) Close() error

Close ends the websocket connection and ensures all requests are finished.

func (*Client) Listen

func (c *Client) Listen() error

Listen starts the giving client and begins reading the websocket connection.

func (*Client) Send

func (c *Client) Send(data []byte, flush bool) error

Send delivers a binary data to the websocket connection.

func (*Client) SendAll

func (c *Client) SendAll(data []byte, flush bool) error

SendAll delivers a binary data to all websocket connections.

func (*Client) Wait

func (c *Client) Wait()

Wait awaits the closure of the giving client.

type RequestOriginValidator

type RequestOriginValidator func(*http.Request) bool

RequestOriginValidator defines a function which validates a request origin for a websocket request.

type SocketAttr

type SocketAttr struct {
	Authenticate       bool
	MessageCompression bool
	Addr               string
	SkipCORS           bool
	TLSConfig          *tls.Config
	Headers            map[string]string
	Credential         octo.AuthCredential
	OriginValidator    RequestOriginValidator
}

SocketAttr defines a attribute struct for defining options for the WebsocketServer struct.

type SocketServer

type SocketServer struct {
	Attr SocketAttr
	// contains filtered or unexported fields
}

SocketServer defines a struct implements the http.ServeHTTP interface which handles servicing http requests for websockets.

func New

func New(instruments octo.Instrumentation, attr SocketAttr) *SocketServer

New returns a new instance of a SocketServer.

func (*SocketServer) Close

func (s *SocketServer) Close() error

Close ends the websocket connection and ensures all requests are finished.

func (*SocketServer) Credential

func (s *SocketServer) Credential() octo.AuthCredential

Credential returns the crendentials for the giving server.

func (*SocketServer) Listen

func (s *SocketServer) Listen(system server.System) error

Listen begins the initialization of the websocket server.

func (*SocketServer) ServeHTTP

func (s *SocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.ServeHTTP interface method to handle http request converted to websockets request.

func (*SocketServer) Wait

func (s *SocketServer) Wait()

Wait awaits the closure of the giving client.

type Transmission

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

Transmission defines a struct for handling responses from a transmission.System object.

func (*Transmission) Close

func (t *Transmission) Close() error

Close ends the internal conneciton.

func (*Transmission) Contact

func (t *Transmission) Contact() (octo.Contact, octo.Contact)

Contact returns the giving information for the internal client and server.

func (*Transmission) Ctx

func (t *Transmission) Ctx() context.Context

Ctx returns the context that is related to this object.

func (*Transmission) Send

func (t *Transmission) Send(data []byte, flush bool) error

Send pipes the giving data down the provided pipeline.

func (*Transmission) SendAll

func (t *Transmission) SendAll(data []byte, flush bool) error

SendAll pipes the giving data down the provided pipeline.

Jump to

Keyboard shortcuts

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