Documentation ¶
Index ¶
- Constants
- func AllSendMessages(appId uint32, userId string, data string)
- func ClearTimeoutConnections()
- func GetManagerInfo(isDebug string) (managerInfo map[string]interface{})
- func GetUserKey(appId uint32, userId string) (key string)
- func GetUserList(appId uint32) (userList []string)
- func InitClientManager(cb func(client *Client, message []byte))
- func Register(key string, value ICmdWsHandler)
- func WsBeegoPage(w http.ResponseWriter, req *http.Request)
- func WsGinPage(c *gin.Context)
- type Client
- func (c *Client) GetKey() (key string)
- func (c *Client) Heartbeat(currentTime int64)
- func (c *Client) IsHeartbeatTimeout(currentTime int64) (timeout bool)
- func (c *Client) IsLogin() (isLogin bool)
- func (c *Client) Login(appId uint32, userId string, loginTime int64)
- func (c *Client) OnPacket(addr string, data []byte)
- func (c *Client) ProcessData(message []byte)
- func (c *Client) SendMsg(msg []byte)
- func (c *Client) SendPbMsg(data1 []byte, data2 []byte)
- type ClientManager
- func (manager *ClientManager) AddClients(client *Client)
- func (manager *ClientManager) AddUsers(key string, client *Client)
- func (manager *ClientManager) BroadcastByZone(zone int, header []byte, body []byte)
- func (manager *ClientManager) ClientsRange(f func(client *Client, value bool) (result bool))
- func (manager *ClientManager) DelClients(client *Client)
- func (manager *ClientManager) DelUsers(client *Client) (result bool)
- func (manager *ClientManager) EventLogin(login *login)
- func (manager *ClientManager) EventRegister(client *Client)
- func (manager *ClientManager) EventUnregister(client *Client)
- func (manager *ClientManager) GetClients() (clients map[*Client]bool)
- func (manager *ClientManager) GetClientsLen() (clientsLen int)
- func (manager *ClientManager) GetUserClient(appId uint32, userId string) (client *Client)
- func (manager *ClientManager) GetUserClients() (clients []*Client)
- func (manager *ClientManager) GetUserKeys() (userKeys []string)
- func (manager *ClientManager) GetUserList(appId uint32) (userList []string)
- func (manager *ClientManager) GetUsersLen() (userLen int)
- func (manager *ClientManager) InClient(client *Client) (ok bool)
- func (manager *ClientManager) KickById(uid uint64, reason g1_protocol.EKickOutReason)
- func (manager *ClientManager) SendByUid(uid uint64, data1 []byte, data2 []byte) error
- type ICmdWsHandler
Constants ¶
View Source
const (
DefaultAppId = 101 // 默认平台Id
)
Variables ¶
This section is empty.
Functions ¶
func GetManagerInfo ¶
************************* manager info ************************************** 获取管理者信息
func InitClientManager ¶
func Register ¶
func Register(key string, value ICmdWsHandler)
func WsBeegoPage ¶
func WsBeegoPage(w http.ResponseWriter, req *http.Request)
WsBeegoPage is beego websocket handler
Types ¶
type Client ¶
type Client struct { Addr string // 客户端地址 Socket *websocket.Conn // 用户连接 Send chan []byte // 待发送的数据 AppId uint32 // 登录的平台Id app/web/ios UserId string // 用户Id,用户登录以后才有 FirstTime int64 // 首次连接事件 HeartbeatTime int64 // 用户上次心跳时间 LoginTime int64 // 登录时间 登录以后才有 }
用户连接
func (*Client) IsHeartbeatTimeout ¶
心跳超时
type ClientManager ¶
type ClientManager struct { Clients map[*Client]bool // 全部的连接 ClientsLock sync.RWMutex // 读写锁 Users map[string]*Client // 登录的用户 // appId+uuid UserLock sync.RWMutex // 读写锁 Register chan *Client // 连接连接处理 Login chan *login // 用户登录处理 Unregister chan *Client // 断开连接处理程序 Broadcast chan []byte // 广播 向全部成员发送数据 HandlerFunc func(client *Client, message []byte) }
连接管理
func NewClientManager ¶
func NewClientManager() (clientManager *ClientManager)
func NewWsClientMgr ¶
func NewWsClientMgr() *ClientManager
func (*ClientManager) AddUsers ¶
func (manager *ClientManager) AddUsers(key string, client *Client)
添加用户
func (*ClientManager) BroadcastByZone ¶
func (manager *ClientManager) BroadcastByZone(zone int, header []byte, body []byte)
func (*ClientManager) ClientsRange ¶
func (manager *ClientManager) ClientsRange(f func(client *Client, value bool) (result bool))
遍历
func (*ClientManager) DelUsers ¶
func (manager *ClientManager) DelUsers(client *Client) (result bool)
删除用户
func (*ClientManager) EventRegister ¶
func (manager *ClientManager) EventRegister(client *Client)
用户建立连接事件
func (*ClientManager) EventUnregister ¶
func (manager *ClientManager) EventUnregister(client *Client)
用户断开连接
func (*ClientManager) GetClients ¶
func (manager *ClientManager) GetClients() (clients map[*Client]bool)
GetClients
func (*ClientManager) GetClientsLen ¶
func (manager *ClientManager) GetClientsLen() (clientsLen int)
GetClientsLen
func (*ClientManager) GetUserClient ¶
func (manager *ClientManager) GetUserClient(appId uint32, userId string) (client *Client)
获取用户的连接
func (*ClientManager) GetUserClients ¶
func (manager *ClientManager) GetUserClients() (clients []*Client)
获取用户的key
func (*ClientManager) GetUserKeys ¶
func (manager *ClientManager) GetUserKeys() (userKeys []string)
获取用户的key
func (*ClientManager) GetUserList ¶
func (manager *ClientManager) GetUserList(appId uint32) (userList []string)
获取用户的key
func (*ClientManager) GetUsersLen ¶
func (manager *ClientManager) GetUsersLen() (userLen int)
GetClientsLen
func (*ClientManager) InClient ¶
func (manager *ClientManager) InClient(client *Client) (ok bool)
func (*ClientManager) KickById ¶
func (manager *ClientManager) KickById(uid uint64, reason g1_protocol.EKickOutReason)
kick
type ICmdWsHandler ¶
func GetHandlers ¶
func GetHandlers(key string) (value ICmdWsHandler, ok bool)
Click to show internal directories.
Click to hide internal directories.