awebsocket

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserKey

func GetUserKey(appId string, userId string) string

GetUserKey 获取用户key

Types

type Client

type Client struct {
	Clients     map[*Connection]bool   // 全部的连接
	ClientsLock sync.RWMutex           // 读写锁
	Users       map[string]*Connection // 登录的用户
	UserLock    sync.RWMutex           // 读写锁
	Register    chan *Connection       // 连接通道处理
	Login       chan *Login            // 用户登录通道处理
	Close       chan *Connection       // 断开连接处理程序
	Broadcast   chan []byte            // 广播消息通道处理
}

Client 客户端连接管理

func NewClient

func NewClient() (clientManager *Client)

NewClient 默认初始化客户端

func (*Client) AddClients

func (get *Client) AddClients(client *Connection)

AddClients Adding a connection 添加客户端

func (*Client) AddUsers

func (get *Client) AddUsers(key string, connection *Connection)

AddUsers 添加用户

func (*Client) DeleteClients

func (get *Client) DeleteClients(client *Connection)

DeleteClients Delete client<删除客户端>

func (*Client) DeleteUsers

func (get *Client) DeleteUsers(connection *Connection) (result bool)

DeleteUsers Delete user<删除用户>

func (*Client) GetClient

func (get *Client) GetClient() (clients map[*Connection]bool)

GetClient Get client 获取客户端连接

func (*Client) GetClientsCount

func (get *Client) GetClientsCount() int

GetClientsCount Gets the length of the connection<获取客户端的总长度>

func (*Client) GetClientsLoop

func (get *Client) GetClientsLoop(f func(client *Connection, value bool) (result bool))

GetClientsLoop Loop all connections<循环所有的客户端连接>

func (*Client) GetUserClient

func (get *Client) GetUserClient(appId string, userId string) (connection *Connection)

GetUserClient 获取用户的连接

func (*Client) GetUserClients

func (get *Client) GetUserClients() (connection []*Connection)

GetUserClients 获取用户的连接

func (*Client) GetUserKeys

func (get *Client) GetUserKeys() (userKeys []string)

GetUserKeys Get the keys for all users<获取所有的key>

func (*Client) GetUserList

func (get *Client) GetUserList(appId string) (userList []string)

GetUserList 获取用户的key

func (*Client) GetUsersCount

func (get *Client) GetUsersCount() int

GetUsersCount Get the total number of users<获取用户总数>

func (*Client) IsClient

func (get *Client) IsClient(client *Connection) bool

IsClient 是否存在

func (*Client) OnLogin

func (get *Client) OnLogin(login *Login)

OnLogin 用户登录

func (*Client) OnRegister

func (get *Client) OnRegister(connection *Connection)

OnRegister 用户建立连接事件

func (*Client) OnUserLogout

func (get *Client) OnUserLogout(client *Connection)

OnUserLogout 用户断开连接

func (*Client) SendAll

func (get *Client) SendAll(message []byte, connection *Connection)

SendAll 向全部成员(除了自己)发送数据

type Connection

type Connection struct {
	Address       string          // 客户端地址
	AppId         string          // 登录的平台Id
	UserId        string          // 用户标识,用户登录以后才有
	LoginTime     uint64          // 登录时间 登录以后才有
	FirstTime     uint64          // 首次连接事件
	HeartbeatTime uint64          // 用户上次心跳时间
	TimeOut       uint64          // 超时时间
	Socket        *websocket.Conn // 用户连接
	ReadChan      chan []byte     // 读取消息通道
	WriteChan     chan []byte     // 写入消息发送客户端
	CloseChan     chan byte       // 关闭通道
	// contains filtered or unexported fields
}

Connection ...

func New

func New(socket *websocket.Conn, address string, firstTime uint64) *Connection

New ...

func (*Connection) Close

func (get *Connection) Close()

Close Close the connection<关闭连接>

func (*Connection) GetHeartbeat

func (get *Connection) GetHeartbeat(currentTime uint64) bool

GetHeartbeat 获取心跳是否超时

func (*Connection) GetLogin

func (get *Connection) GetLogin() bool

GetLogin 获取是否登录

func (*Connection) ReadMessage

func (get *Connection) ReadMessage() (data []byte, err error)

ReadMessage Read client messages<读取客户端消息>

func (*Connection) SetHeartbeat

func (get *Connection) SetHeartbeat(currentTime uint64)

SetHeartbeat 设置用户心跳

func (*Connection) SetLogin

func (get *Connection) SetLogin(appId string, userId string, loginTime uint64)

SetLogin 设置用户登录

func (*Connection) SetTimeOut

func (get *Connection) SetTimeOut(TimeOut uint64)

SetTimeOut 设置超时时间

func (*Connection) WriteMessage

func (get *Connection) WriteMessage(data []byte) (err error)

WriteMessage Write message sending client(写入消息发送客户端)

type Login

type Login struct {
	AppId  string
	UserId string
	Client *Connection
}

Login 用户登录

func (*Login) GetUserKey

func (get *Login) GetUserKey() (key string)

GetUserKey 获取用户的Key

Jump to

Keyboard shortcuts

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