websocket

package
v0.0.0-...-4e4d147 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnClosed = errors.New("Connection is closed")
View Source
var (
	ErrNoUrlProvided = errors.New("No URL provided")
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(websocketURL string, connHandler NewConnHandler) (*Client, error)

func (*Client) Connection

func (c *Client) Connection() *Conn

type Conn

type Conn struct {
	ID          string
	ReceiveChan chan []byte

	ClientAddr net.Addr
	// contains filtered or unexported fields
}

Conn wraps a websocket.Conn to provide channels for reading and writing

func (*Conn) LocalAddrStr

func (c *Conn) LocalAddrStr() string

func (*Conn) Send

func (c *Conn) Send(msg []byte) error

Send sends a message through the connection. It is safe to use if the connection is closed, because it will return an error indicating that condition.

type NewConnHandler

type NewConnHandler func(*Conn)

NewConnHandler is called whenever a new connection to this WebSocket server is created. It receives the relevant Conn, allowing for easy access to its ReceiveChan and SendChan.

type Server

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

Server is a WebSocket server.

func NewServer

func NewServer(newConnHandler NewConnHandler) (*Server, error)

NewServer creates and returns a new WebSocket server.

func (*Server) Connection

func (s *Server) Connection(key string) *Conn

func (*Server) Connections

func (s *Server) Connections() []*Conn

func (*Server) ServeHTTP

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

ServeHTTP implements the http.Handler interface so that it can be placed inside an http.ServeMux or other router.

Jump to

Keyboard shortcuts

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