wslync

package module
v0.0.0-...-08d8efc Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpText        ws.OpCode = 0x1
	OpBinary      ws.OpCode = 0x2
	OpInvalidData ws.OpCode = 0x5
	OpConnected   ws.OpCode = 0x6
	OpPingTimeout ws.OpCode = 0x7
	OpClose       ws.OpCode = 0x8
	OpPing        ws.OpCode = 0x9
	OpPong        ws.OpCode = 0xa

	StatusNormalClosure           ws.StatusCode = 1000
	StatusGoingAway               ws.StatusCode = 1001
	StatusProtocolError           ws.StatusCode = 1002
	StatusUnsupportedData         ws.StatusCode = 1003
	StatusNoMeaningYet            ws.StatusCode = 1004
	StatusInvalidFramePayloadData ws.StatusCode = 1007
	StatusPolicyViolation         ws.StatusCode = 1008
	StatusMessageTooBig           ws.StatusCode = 1009
	StatusMandatoryExt            ws.StatusCode = 1010
	StatusInternalServerError     ws.StatusCode = 1011
	StatusTLSHandshake            ws.StatusCode = 1015
)

External opcode defined to be more specifically about some events

Variables

View Source
var (
	// ErrCallbackISNil defined when user did not set callback func
	ErrCallbackISNil = errors.New("Callback should not be nil")

	// ErrUserNotFound in session list
	ErrUserNotFound = errors.New("UserID not found")
)

Functions

func GenerateLetter

func GenerateLetter(length int) string

GenerateLetter with specified length

Types

type ListenerBuilderConfig

type ListenerBuilderConfig struct {
	ReadBufferSize  int
	WriteBufferSize int
	Port            int
	IDLength        int
	WorkerCount     int
	PingFailCount   int
	QueueSize       uint64
	PingInterval    time.Duration
}

ListenerBuilderConfig is used when you want to constructing listener system use DefaultConfig for more safety

func DefaultConfig

func DefaultConfig() *ListenerBuilderConfig

DefaultConfig to construct websocket server

func (*ListenerBuilderConfig) Build

Build ListenerSystem from config

type ListenerSystem

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

ListenerSystem will listen all the traffic including new connection, bi-directional communication, etc.

func (*ListenerSystem) Callback

func (ls *ListenerSystem) Callback(cb func(*Payload) error) error

Callback used to set an action to incoming message

func (*ListenerSystem) CloseClient

func (ls *ListenerSystem) CloseClient(id string, statusCode ws.StatusCode) error

CloseClient without any specified messaage

func (*ListenerSystem) CloseClientWithMessage

func (ls *ListenerSystem) CloseClientWithMessage(id string, statusCode ws.StatusCode, message string) error

CloseClientWithMessage return err if connection id not found or connection already closed

func (*ListenerSystem) Listen

func (ls *ListenerSystem) Listen() error

Listen every connection, message, event, etc.

func (*ListenerSystem) SendBinary

func (ls *ListenerSystem) SendBinary(id string, data []byte) error

SendBinary byte to specified user

func (*ListenerSystem) SendPing

func (ls *ListenerSystem) SendPing(id string)

SendPing to user to check whether the user is still active

func (*ListenerSystem) SendText

func (ls *ListenerSystem) SendText(id string, text []byte) error

SendText to specified user as a byte

type Payload

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

Payload for storing incoming message from client

func (*Payload) Bytes

func (p *Payload) Bytes() []byte

Bytes return byte from buffer

func (*Payload) ClientID

func (p *Payload) ClientID() string

ClientID return string of client id

func (*Payload) Code

func (p *Payload) Code() ws.OpCode

Code of specified events

func (*Payload) Flush

func (p *Payload) Flush()

Flush buffer or returning it to pool if you not call this function, perhaps your bytes never be pooled

func (*Payload) ToString

func (p *Payload) ToString() string

ToString from buffer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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