Documentation ¶
Index ¶
- func GetUserKey(appId string, userId string) string
- type Client
- func (get *Client) AddClients(client *Connection)
- func (get *Client) AddUsers(key string, connection *Connection)
- func (get *Client) DeleteClients(client *Connection)
- func (get *Client) DeleteUsers(connection *Connection) (result bool)
- func (get *Client) GetClient() (clients map[*Connection]bool)
- func (get *Client) GetClientsCount() int
- func (get *Client) GetClientsLoop(f func(client *Connection, value bool) (result bool))
- func (get *Client) GetUserClient(appId string, userId string) (connection *Connection)
- func (get *Client) GetUserClients() (connection []*Connection)
- func (get *Client) GetUserKeys() (userKeys []string)
- func (get *Client) GetUserList(appId string) (userList []string)
- func (get *Client) GetUsersCount() int
- func (get *Client) IsClient(client *Connection) bool
- func (get *Client) OnLogin(login *Login)
- func (get *Client) OnRegister(connection *Connection)
- func (get *Client) OnUserLogout(client *Connection)
- func (get *Client) SendAll(message []byte, connection *Connection)
- type Connection
- func (get *Connection) Close()
- func (get *Connection) GetHeartbeat(currentTime uint64) bool
- func (get *Connection) GetLogin() bool
- func (get *Connection) ReadMessage() (data []byte, err error)
- func (get *Connection) SetHeartbeat(currentTime uint64)
- func (get *Connection) SetLogin(appId string, userId string, loginTime uint64)
- func (get *Connection) SetTimeOut(TimeOut uint64)
- func (get *Connection) WriteMessage(data []byte) (err error)
- type Login
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*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 ¶
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 ¶
GetUserKeys Get the keys for all users<获取所有的key>
func (*Client) GetUserList ¶
GetUserList 获取用户的key
func (*Client) GetUsersCount ¶
GetUsersCount Get the total number of users<获取用户总数>
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 (*Connection) GetHeartbeat ¶
func (get *Connection) GetHeartbeat(currentTime uint64) bool
GetHeartbeat 获取心跳是否超时
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) WriteMessage ¶
func (get *Connection) WriteMessage(data []byte) (err error)
WriteMessage Write message sending client(写入消息发送客户端)