websocket

package
v0.0.0-...-503c977 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConnNotFound = errors.New("conn not found in server !")

Functions

func NewConnection

func NewConnection(id uint32, conn *websocket.Conn, server xnet.Server) xnet.Connection

func NewDispatch

func NewDispatch() xnet.Dispatcher

func NewRequest

func NewRequest(msg xnet.Message, conn *Connection) xnet.Request

Types

type Connection

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

func (*Connection) GetAttribute

func (c *Connection) GetAttribute(key string) (any, bool)

func (*Connection) GetConnId

func (c *Connection) GetConnId() string

func (*Connection) SendBufferMesg

func (c *Connection) SendBufferMesg(id uint32, data []byte) error

func (*Connection) SendMsg

func (c *Connection) SendMsg(id uint32, data []byte) error

func (*Connection) SetAttribute

func (c *Connection) SetAttribute(key string, val any)

func (*Connection) Start

func (c *Connection) Start()

func (*Connection) StartReader

func (c *Connection) StartReader()

func (*Connection) StartWriter

func (c *Connection) StartWriter()

func (*Connection) Stop

func (c *Connection) Stop()

type Disptach

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

func (*Disptach) Handle

func (d *Disptach) Handle(req xnet.Request)

func (*Disptach) HandleFunc

func (d *Disptach) HandleFunc(id uint8, handler xnet.HandleFunc)

添加路由

func (*Disptach) SentToTaskQueue

func (d *Disptach) SentToTaskQueue(req xnet.Request)

func (*Disptach) StartWookerPool

func (d *Disptach) StartWookerPool(poosize uint32, queueLent uint32)

type Message

type Message struct {
	Id      uint32
	Len     uint32
	DataLen uint32

	Data []byte
}

func NewMessage

func NewMessage(id uint32, data []byte) *Message

func (*Message) GetData

func (m *Message) GetData() []byte

获取消息内容

func (*Message) GetMsgId

func (m *Message) GetMsgId() uint32

func (*Message) GetMsgLen

func (m *Message) GetMsgLen() uint32

func (*Message) SetData

func (m *Message) SetData(data []byte)

func (*Message) SetDataLen

func (m *Message) SetDataLen(len uint32)

func (*Message) SetMsgId

func (m *Message) SetMsgId(id uint32)

type Request

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

func (*Request) GetConnection

func (r *Request) GetConnection() xnet.Connection

func (*Request) GetData

func (r *Request) GetData() []byte

func (*Request) GetMsgID

func (r *Request) GetMsgID() uint32

type Server

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

func Default

func Default() *Server

func NewServer

func NewServer(opt *xnet.ServerOption) *Server

func (*Server) ChatWith

func (s *Server) ChatWith(uid string, msgID uint32, data []byte) error

func (*Server) FactoryConnectionId

func (s *Server) FactoryConnectionId() uint32

获取链接id

func (*Server) GetAcceptFunc

func (s *Server) GetAcceptFunc() func([]byte) (bool, xnet.IdCreater)

func (*Server) GetConnManager

func (s *Server) GetConnManager() *xnet.ConnManager

func (*Server) GetConnectionByID

func (s *Server) GetConnectionByID(id string) (xnet.Connection, bool)

根据用户id 获取单个链接id

func (*Server) GetDispatcher

func (s *Server) GetDispatcher() xnet.Dispatcher

获取路由管理

func (*Server) GetID

func (s *Server) GetID() int64

func (*Server) GetPool

func (s *Server) GetPool() *sync.Pool

func (*Server) GetServerOpt

func (s *Server) GetServerOpt() *xnet.ServerOption

获取server opt

func (*Server) GetStates

func (s *Server) GetStates() xnet.States

func (*Server) RemoveConnectionId

func (s *Server) RemoveConnectionId(id uint32)

移除链接id

func (*Server) Serve

func (s *Server) Serve()

启动一个服务

func (*Server) ServeWs

func (s *Server) ServeWs(w http.ResponseWriter, r *http.Request)

握手并启动链接处理

func (*Server) SetAcceptFunc

func (s *Server) SetAcceptFunc(accept func([]byte) (bool, xnet.IdCreater))

func (*Server) SetDistpatcher

func (s *Server) SetDistpatcher(dispatch xnet.Dispatcher)

设置路由管理

func (*Server) SetHandShakeFaildFunc

func (s *Server) SetHandShakeFaildFunc(handler func(w http.ResponseWriter))

设置握手失败处理方法

func (*Server) SetPoolSize

func (s *Server) SetPoolSize(size uint32)

func (*Server) Start

func (s *Server) Start()

停止服务

func (*Server) Stop

func (s *Server) Stop()

停止服务

type Subscribe

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

func NewSubscribe

func NewSubscribe(name string) *Subscribe

func (*Subscribe) Tag

func (s *Subscribe) Tag() string

type Wire

type Wire struct {
}

func (*Wire) GetHeadLen

func (w *Wire) GetHeadLen() uint32

func (*Wire) Pack

func (w *Wire) Pack(msg xnet.Message) ([]byte, error)

func (*Wire) Unpack

func (w *Wire) Unpack(data []byte) (xnet.Message, error)

Jump to

Keyboard shortcuts

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