websocket

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2018 License: MIT Imports: 10 Imported by: 0

README

GWS (Go WebSocket)

author: xdrm-brackets

Websocket implementation in go. It features a server as well as a client.

Key objectives

objective my definition
fast response time less than 1ms at least
reliable gracefully handle usage/network/... errors
secure add available cryptography (stream)
compatible respect RFC-6455 as well as actual browser implementations
generic use golang implicit interfaces to make the code reusable for all (most) cases

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CloseFrame = fmt.Errorf("Received close Frame")
View Source
var ErrInvalidCloseStatus = fmt.Errorf("Received invalid close status")
View Source
var ErrInvalidFragment = fmt.Errorf("Received invalid fragmentation")
View Source
var ErrInvalidOpCode = fmt.Errorf("Received invalid OpCode")
View Source
var ErrInvalidPayload = fmt.Errorf("Received invalid utf8 payload")
View Source
var ErrInvalidSize = fmt.Errorf("Received invalid payload size")
View Source
var ErrReservedBits = fmt.Errorf("Received reserved bits")
View Source
var ErrTooLongControlFrame = fmt.Errorf("Received a control frame that is fragmented or too long")
View Source
var ErrUnexpectedContinuation = fmt.Errorf("Received unexpected continuation frame")
View Source
var ErrUnmaskedFrame = fmt.Errorf("Received unmasked frame")

Functions

This section is empty.

Types

type Client

type Client struct {
	Protocol  string      // choosen protocol (Sec-WebSocket-Protocol)
	Arguments [][]string  // URI parameters, index 0 is full URI, then matching groups
	Store     interface{} // store (for client implementation-specific data)
}

Represents available information about a client

type Controller

type Controller struct {
	URI *parser.Scheme // uri scheme
	Fun ControllerFunc // controller function
}

Represents a websocket controller

type ControllerFunc

type ControllerFunc func(*Client, <-chan Message, chan<- Message, chan<- Message)

Represents a websocket controller callback function

type ControllerSet

type ControllerSet struct {
	Def *Controller   // default controller
	Uri []*Controller // uri controllers
}

Represents a controller set

func (*ControllerSet) Match

func (s *ControllerSet) Match(uri string) (*Controller, [][]string)

Match finds a controller for a given URI also it returns the matching string patterns

type Message

type Message struct {
	Final bool
	Type  MessageType
	Size  uint
	Data  []byte
}

Represents a websocket message

func (Message) Send

func (m Message) Send(writer io.Writer) error

Send sends a frame over a socket

type MessageError

type MessageError uint16

Lists websocket close status

const (
	NONE                MessageError = 0
	NORMAL              MessageError = 1000
	GOING_AWAY          MessageError = 1001
	PROTOCOL_ERR        MessageError = 1002
	UNACCEPTABLE_OPCODE MessageError = 1003
	INVALID_PAYLOAD     MessageError = 1007 // utf8
	MESSAGE_TOO_LARGE   MessageError = 1009
)

type MessageType

type MessageType byte

Lists websocket message types

const (
	CONTINUATION MessageType = 0x00
	TEXT         MessageType = 0x01
	BINARY       MessageType = 0x02
	CLOSE        MessageType = 0x08
	PING         MessageType = 0x09
	PONG         MessageType = 0x0a
)

type Server

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

Represents a websocket server

func CreateServer

func CreateServer(host string, port uint16) *Server

CreateServer creates a server for a specific HOST and PORT

func (*Server) Bind

func (s *Server) Bind(uri string, f ControllerFunc) error

Bind binds a controller to an URI scheme

func (*Server) BindDefault

func (s *Server) BindDefault(f ControllerFunc)

BindDefault binds a default controller it will be called if the URI does not match another controller

func (*Server) Launch

func (s *Server) Launch() error

Launch launches the websocket server

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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