Documentation ¶
Index ¶
- func AllSendMessages(appId uint32, userId string, data string)
- func CheckUserOnline(appId uint32, userId string) (online bool)
- func ClearTimeoutConnections()
- func GetAppIds() []uint32
- func GetManagerInfo(isDebug string) (managerInfo map[string]interface{})
- func GetServer() (server *models.Server)
- func GetUserKey(appId uint32, userId string) (key string)
- func GetUserList() (userList []string)
- func HeartbeatController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{})
- func InAppIds(appId uint32) (inAppId bool)
- func IsLocal(server *models.Server) (isLocal bool)
- func LoginController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{})
- func ProcessData(client *Client, message []byte)
- func Register(key string, value DisposeFunc)
- func SendUserMessage(appId uint32, userId string, msgId, message string) (sendResults bool, err error)
- func SendUserMessageAll(appId uint32, userId string, msgId, cmd, message string) (sendResults bool, err error)
- func SendUserMessageLocal(appId uint32, userId string, data string) (sendResults bool, err error)
- func StartWebSocket()
- func UserList() (userList []string)
- type Client
- func (c *Client) GetKey() (key string)
- func (c *Client) Heartbeat(currentTime uint64)
- func (c *Client) IsHeartbeatTimeout(currentTime uint64) (timeout bool)
- func (c *Client) IsLogin() (isLogin bool)
- func (c *Client) Login(appId uint32, userId string, loginTime uint64)
- func (c *Client) SendMsg(msg []byte)
- type ClientManager
- func (manager *ClientManager) AddClients(client *Client)
- func (manager *ClientManager) AddUsers(key string, client *Client)
- func (manager *ClientManager) DelClients(client *Client)
- func (manager *ClientManager) DelUsers(key string)
- func (manager *ClientManager) EventLogin(login *login)
- func (manager *ClientManager) EventRegister(client *Client)
- func (manager *ClientManager) EventUnregister(client *Client)
- func (manager *ClientManager) GetUserClient(appId uint32, userId string) (client *Client)
- type DisposeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetManagerInfo ¶
************************* manager info ************************************** 获取管理者信息
func HeartbeatController ¶
func HeartbeatController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{})
心跳接口
func LoginController ¶
func LoginController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{})
用户登录
func SendUserMessage ¶
func SendUserMessage(appId uint32, userId string, msgId, message string) (sendResults bool, err error)
给用户发送消息
func SendUserMessageAll ¶
func SendUserMessageAll(appId uint32, userId string, msgId, cmd, message string) (sendResults bool, err error)
给全体用户发消息
func SendUserMessageLocal ¶
给本机用户发送消息
Types ¶
type Client ¶
type Client struct { Addr string // 客户端地址 Socket *websocket.Conn // 用户连接 Send chan []byte // 待发送的数据 AppId uint32 // 登录的平台Id app/web/ios UserId string // 用户Id,用户登录以后才有 FirstTime uint64 // 首次连接事件 HeartbeatTime uint64 // 用户上次心跳时间 LoginTime uint64 // 登录时间 登录以后才有 }
用户连接
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 // 广播 向全部成员发送数据 }
连接管理
func NewClientManager ¶
func NewClientManager() (clientManager *ClientManager)
func (*ClientManager) AddUsers ¶
func (manager *ClientManager) AddUsers(key string, client *Client)
添加用户
func (*ClientManager) EventRegister ¶
func (manager *ClientManager) EventRegister(client *Client)
用户建立连接事件
func (*ClientManager) EventUnregister ¶
func (manager *ClientManager) EventUnregister(client *Client)
用户断开连接
func (*ClientManager) GetUserClient ¶
func (manager *ClientManager) GetUserClient(appId uint32, userId string) (client *Client)
获取用户的连接
Click to show internal directories.
Click to hide internal directories.