ws

package
v0.1.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

WebSocket

websocket.go

负责管理websocket客户端

client.go

websocket客户端连接对象

Documentation

Index

Constants

View Source
const (
	Default = iota
	Running
	Exit
)

Client states

View Source
const (
	SendQueueLen    = 5
	ReceiveQueueLen = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	URL        string
	Conn       *websocket.Conn
	SendMsg    chan []byte
	ReceiveMsg chan []byte
	CloseChan  chan struct{}
	Status     int
	ID         string
}

func NewClient

func NewClient(opts ...Options) *Client

func (*Client) Read

func (c *Client) Read()

func (*Client) Run

func (c *Client) Run() error

func (*Client) UpGrader

func (c *Client) UpGrader(w http.ResponseWriter, r *http.Request) error

func (*Client) Write

func (c *Client) Write()

type ClientManager

type ClientManager struct {
	ClientCnt uint32

	Status int
	// contains filtered or unexported fields
}

func GetManager

func GetManager(logger log.Logger) *ClientManager

func NewClientManager

func NewClientManager(logger log.Logger) *ClientManager

func NewClientManagerWithRun

func NewClientManagerWithRun(logger log.Logger) *ClientManager

func (*ClientManager) GetClientMsgChan

func (m *ClientManager) GetClientMsgChan(url string, id string) chan []byte

func (*ClientManager) LogOut

func (m *ClientManager) LogOut(client *Client) error

func (*ClientManager) Register

func (m *ClientManager) Register(client *Client) error

func (*ClientManager) SendMsgToGroup

func (m *ClientManager) SendMsgToGroup(url string, msg []byte)

func (*ClientManager) Start

func (m *ClientManager) Start(ctx context.Context) error

func (*ClientManager) Stop

func (m *ClientManager) Stop(ctx context.Context) error

type Options

type Options func(*Client)

func WithID

func WithID(id string) Options

func WithURL

func WithURL(url string) Options

func WithUUID

func WithUUID() Options

Jump to

Keyboard shortcuts

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