websocket

package module
Version: v0.0.0-...-f41656e Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2018 License: MIT Imports: 9 Imported by: 0

README

websocket Build Status GoDoc

A wrapper around github.com/gorilla/websocket to make writing WebSocket servers and clients in Go simpler. Instead of writing a bunch of code to track connections and shuffle data into and out of them, you can just focus on just writing and reading arbitrary bytes.

Creators

  • Kathryn Hendrickson
  • Sidney Kochman

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL