gate

package
v0.0.0-...-be98215 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OPEN uint8 = iota
	KICK
)
View Source
const (
	OnOpen uint8 = iota
	OnMessage
	OnClose
	OnPong
)

Variables

View Source
var (
	ErrUpgrade     = errors.New("Can \"Upgrade\" only to \"WebSocket\"")
	ErrConnection  = errors.New("\"Connection\" must be \"Upgrade\"")
	ErrCrossOrigin = errors.New("Cross origin websockets not allowed")
	ErrSecVersion  = errors.New("HTTP/1.1 Upgrade Required\r\nSec-WebSocket-Version: 13\r\n\r\n")
	ErrSecKey      = errors.New("\"Sec-WebSocket-Key\" must not be  nil")
	ErrHijacker    = errors.New("Not implement http.Hijacker")
)
View Source
var (
	ErrReservedBits    = errors.New("Reserved_bits show using undefined extensions")
	ErrFrameOverload   = errors.New("Control frame payload overload")
	ErrFrameFragmented = errors.New("Control frame must not be fragmented")
	ErrInvalidOpcode   = errors.New("Invalid frame opcode")
)

Functions

func ResponseStart

func ResponseStart(service *cham.Service, args ...interface{}) cham.Dispatch

func Start

func Start(service *cham.Service, args ...interface{}) cham.Dispatch

Types

type Backend

type Backend interface {
	Write(data []byte) error
	Close()
}

type Conf

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

func NewConf

func NewConf(address string, maxclient uint32, path string) *Conf

type Gate

type Gate struct {
	Source cham.Address
	// contains filtered or unexported fields
}

func New

func New(source cham.Address, service *cham.Service) *Gate

func (*Gate) Write

func (g *Gate) Write(session uint32, data []byte) (err error)

type Option

type Option struct {
	Handler      WsHandler // 处理器, default WsDefaultHandler
	MaskOutgoing bool      //发送frame是否mask, default false
}

type TcpBackend

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

func (*TcpBackend) Close

func (t *TcpBackend) Close()

func (*TcpBackend) Write

func (t *TcpBackend) Write(data []byte) (err error)

type Websocket

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

func NewWebsocket

func NewWebsocket(w http.ResponseWriter, r *http.Request, opt *Option, session uint32, gate *Gate) (*Websocket, error)

func (*Websocket) Close

func (ws *Websocket) Close(code uint16, reason []byte)

func (*Websocket) Recv

func (ws *Websocket) Recv() ([]byte, error)

func (*Websocket) RecvFrame

func (ws *Websocket) RecvFrame() (final bool, message []byte, err error)

func (*Websocket) SendBinary

func (ws *Websocket) SendBinary(data []byte) error

func (*Websocket) SendFrame

func (ws *Websocket) SendFrame(fin bool, opcode byte, data []byte) error

func (*Websocket) SendPing

func (ws *Websocket) SendPing(data []byte) error

func (*Websocket) SendPong

func (ws *Websocket) SendPong(data []byte) error

func (*Websocket) SendText

func (ws *Websocket) SendText(data []byte) error

func (*Websocket) Start

func (ws *Websocket) Start()

type WebsocketBackend

type WebsocketBackend struct {
	*Websocket
}

func (*WebsocketBackend) Close

func (w *WebsocketBackend) Close()

func (*WebsocketBackend) Write

func (w *WebsocketBackend) Write(data []byte) error

type WsDefaultHandler

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

func (WsDefaultHandler) CheckOrigin

func (wd WsDefaultHandler) CheckOrigin(origin, host string) bool

func (WsDefaultHandler) OnClose

func (wd WsDefaultHandler) OnClose(ws *Websocket, code uint16, reason []byte)

func (WsDefaultHandler) OnMessage

func (wd WsDefaultHandler) OnMessage(ws *Websocket, message []byte)

func (WsDefaultHandler) OnOpen

func (wd WsDefaultHandler) OnOpen(ws *Websocket)

func (WsDefaultHandler) OnPong

func (wd WsDefaultHandler) OnPong(ws *Websocket, data []byte)

type WsHandler

type WsHandler interface {
	CheckOrigin(origin, host string) bool
	OnOpen(ws *Websocket)
	OnMessage(ws *Websocket, message []byte)
	OnClose(ws *Websocket, code uint16, reason []byte)
	OnPong(ws *Websocket, data []byte)
}

Jump to

Keyboard shortcuts

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