ws

package
v0.0.0-...-35fa672 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionClosed = errors.New("qws:session has closed yet!")
	ErrSessionFulled = errors.New("qws:session buffer is full!")
	ErrServerDown    = errors.New("qws:server has down!")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// 写超时
	WriteTimeout time.Duration
	TTLTimeout   time.Duration
	// 一个消息最大的size
	MaxMessageSize int64
	// session消息最大的数量
	MessageBufferSize int
}

func DefaultConfig

func DefaultConfig() *Config

type G

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

func (*G) GetSessionById

func (g *G) GetSessionById(id string) *Session

func (*G) ReplaceSessionById

func (g *G) ReplaceSessionById(session *Session, id string)

替换session

type HandleCloseFunc

type HandleCloseFunc func(*Session, int, string)

type HandleEmptyFunc

type HandleEmptyFunc func()

type HandleErrorFunc

type HandleErrorFunc func(*Session, error)

type HandleFilterFunc

type HandleFilterFunc func(*Session) bool

type HandleMessageFunc

type HandleMessageFunc func(*Session, []byte)

type HandleSessionFunc

type HandleSessionFunc func(*Session)

type Packet

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

封包

type Server

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

func New

func New(conf ...*Config) *Server

func (*Server) Broadcast

func (w *Server) Broadcast(msg []byte) error

func (*Server) BroadcastBinary

func (w *Server) BroadcastBinary(msg []byte) error

func (*Server) BroadcastBinaryExcept

func (w *Server) BroadcastBinaryExcept(msg []byte, s *Session) error

func (*Server) BroadcastBinaryFilter

func (w *Server) BroadcastBinaryFilter(msg []byte, fn func(*Session) bool) error

binary broadcast

func (*Server) BroadcastBinaryMultiple

func (w *Server) BroadcastBinaryMultiple(msg []byte, ss []*Session) error

func (*Server) BroadcastExcept

func (w *Server) BroadcastExcept(msg []byte, s *Session) error

func (*Server) BroadcastFilter

func (w *Server) BroadcastFilter(msg []byte, fn func(*Session) bool) error

广播

func (*Server) BroadcastMultiple

func (w *Server) BroadcastMultiple(msg []byte, ss []*Session) error

func (*Server) Close

func (w *Server) Close() error

close

func (*Server) CloseWithMsg

func (w *Server) CloseWithMsg(msg []byte) error

func (*Server) FmtCloseMsg

func (w *Server) FmtCloseMsg(code int, text string) []byte

func (*Server) GetSessionById

func (w *Server) GetSessionById(id string) *Session

func (*Server) HandleClose

func (w *Server) HandleClose(fn HandleCloseFunc)

func (*Server) HandleConnect

func (w *Server) HandleConnect(fn HandleSessionFunc)

func (*Server) HandleDisconnect

func (w *Server) HandleDisconnect(fn HandleSessionFunc)

func (*Server) HandleError

func (w *Server) HandleError(fn HandleErrorFunc)

func (*Server) HandleMessage

func (w *Server) HandleMessage(fn HandleMessageFunc)

func (*Server) HandleMessageBinary

func (w *Server) HandleMessageBinary(fn HandleMessageFunc)

func (*Server) HandleRequest

func (w *Server) HandleRequest(writer http.ResponseWriter, r *http.Request) error

func (*Server) HandleRequestWithKeys

func (w *Server) HandleRequestWithKeys(writer http.ResponseWriter, r *http.Request, keys map[string]interface{}) error

func (*Server) HandleSent

func (w *Server) HandleSent(fn HandleMessageFunc)

func (*Server) HandleSentBinary

func (w *Server) HandleSentBinary(fn HandleMessageFunc)

func (*Server) HandleShutdown

func (w *Server) HandleShutdown(fn HandleEmptyFunc)

func (*Server) IsClosed

func (w *Server) IsClosed() bool

func (*Server) Len

func (w *Server) Len() int

func (*Server) ReplaceSessionById

func (w *Server) ReplaceSessionById(session *Session, id string)

type Session

type Session struct {
	Request *http.Request
	Keys    map[string]interface{}
	// contains filtered or unexported fields
}

func (*Session) Close

func (s *Session) Close() error

func (*Session) CloseWithMsg

func (s *Session) CloseWithMsg(msg []byte) error

func (*Session) Get

func (s *Session) Get(key string) (interface{}, bool)

func (*Session) GetId

func (s *Session) GetId() string

func (*Session) IsClosed

func (s *Session) IsClosed() bool

session 是否关闭

func (*Session) LocalAddr

func (s *Session) LocalAddr() net.Addr

func (*Session) MustGet

func (s *Session) MustGet(key string) interface{}

func (*Session) Ping

func (s *Session) Ping() error

func (*Session) Pong

func (s *Session) Pong() error

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() net.Addr

func (*Session) Set

func (s *Session) Set(key string, val interface{})

kv setting

func (*Session) Write

func (s *Session) Write(msg []byte) error

func (*Session) WriteBinary

func (s *Session) WriteBinary(msg []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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