websockets

package module
v0.0.0-...-1d42e6b Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

分布式websocket手脚架

Documentation

Index

Constants

View Source
const (
	TypeBroadcast  = "type_broadcast"
	TypeOneOnOne   = "type_one_on_one"
	TypeOneToMany  = "type_one_to_many"
	TypeManyToMany = "type_many_to_many"
)

Variables

This section is empty.

Functions

func Listen

func Listen(addr string, pattern string, handler func(http.ResponseWriter, *http.Request))

Types

type Client

type Client struct {
	Id            string
	Send          chan []byte
	IsServer      bool
	CloseCallBack func()

	Server *Server
	// contains filtered or unexported fields
}

func Init

func Init(id string, server *Server, conn *websocket.Conn) *Client

func (*Client) Read

func (c *Client) Read()

Read: Process messages sent by the client

func (*Client) ToGroup

func (c *Client) ToGroup(groupId string, msg interface{}) bool

func (*Client) ToOne

func (c *Client) ToOne(toId string, msg interface{}) bool

func (*Client) Write

func (c *Client) Write()

Write: Send a message to the client

type Manager

type Manager struct {
	Clients cmap.ConcurrentMap
}

func InitManager

func InitManager() *Manager

func (*Manager) Broadcast

func (m *Manager) Broadcast(msg SubscriberBody)

Broadcast 广播

func (*Manager) Get

func (m *Manager) Get(id string) *Client

Get 获取客户端

func (*Manager) Join

func (m *Manager) Join(c *Client) bool

Join 加入

func (*Manager) Leave

func (m *Manager) Leave(c *Client) bool

Leave 离开

type ParserHandler

type ParserHandler func(c *Client, msg interface{})

type Protocol

type Protocol interface {
	Register(protocol int64, t interface{}, handler ParserHandler)
	Receive(c *Client, msg []byte) error
	Send(c *Client, msg SubscriberBody) error
}

Protocol 协议接口

type Server

type Server struct {
	Manager    *Manager
	Protocol   Protocol
	Subscriber Subscriber
}

func InitServer

func InitServer(protocol Protocol, Subscriber Subscriber) *Server

type Subscriber

type Subscriber interface {
	Conn()
	Destroy()
	Producer(c *Client, message SubscriberMessage)
	Consumer(server *Server)
}

Subscriber 订阅器接口

type SubscriberBody

type SubscriberBody struct {
	Protocol  int64
	Data      interface{}
	Condition interface{}
}

type SubscriberMessage

type SubscriberMessage struct {
	Type string
	Body SubscriberBody
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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