cascade

package module
v0.0.0-...-2aec719 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: MIT Imports: 7 Imported by: 12

README

cascade

toy go websocket program

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GzipDecode

func GzipDecode(in []byte) ([]byte, error)

Types

type DisconnectCallback

type DisconnectCallback func(string, error)

type Hub

type Hub struct {
	Upgrader    *websocket.Upgrader
	MaxReadSize int64

	Peers                map[*Peer]bool         // client's map
	PeerRegister         chan *Peer             // channel that notify peer active
	PeerUnregister       chan *Peer             // channel that notify peer inactive
	ByteMessageChannel   chan *HubByteMessage   // message channel
	ObjectMessageChannel chan *HubObjectMessage // named object channel
	ExitChannel          chan int
	Slot                 Slot
}

func NewHub

func NewHub(slot Slot, upgrader *websocket.Upgrader, maxReadSize int64) *Hub

func (*Hub) ConnectAndRun

func (this *Hub) ConnectAndRun(addr string, reconn bool, reconnInterval int, reqHeader http.Header, disconnectCallback DisconnectCallback)

func (*Hub) OnAccept

func (this *Hub) OnAccept(w http.ResponseWriter, r *http.Request)

func (*Hub) Run

func (this *Hub) Run()

func (*Hub) Stop

func (this *Hub) Stop()

type HubByteMessage

type HubByteMessage struct {
	Peer    *Peer
	Message []byte
}

type HubObjectMessage

type HubObjectMessage struct {
	Peer       *Peer
	ObjectName string
	ObjectPtr  interface{}
}

type Peer

type Peer struct {
	Hub            *Hub            // peer's hub
	Conn           *websocket.Conn // websocket connection
	SendChannel    chan []byte     // send channel
	CallbackOnRead func([]byte)    // on read message form peer
	ExtraInfo      interface{}     // extra information
	Header         http.Header     // header
}

func NewPeer

func NewPeer(hub *Hub, conn *websocket.Conn) *Peer

func (*Peer) ReadPump

func (this *Peer) ReadPump(maxReadSize int64)

peer read

func (*Peer) WritePump

func (this *Peer) WritePump()

peer write

type Slot

type Slot interface {
	// peer message
	OnActive(*Peer)
	OnInactive(*Peer)
	OnRead(*Peer, []byte)

	// hub message
	OnHubByteMessage(*HubByteMessage)
	OnHubObjectMessage(*HubObjectMessage)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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