func outerConnectHandler(client *pillx.Response, protocol pillx.IProtocol) { clients[client.GetConn().Id] = client fmt.Printf("client %d 连接到此网关\n", client.GetConn().Id) //频道 chat_channel.Subscribe(client) }
func outerMessageHandler(client *pillx.Response, protocol pillx.IProtocol) { //将客户端协议转化为gateway协议 gatewayProtocol := &pillx.GateWayProtocol{} header := &pillx.GatewayHeader{} gatewayProtocol.Header = header header.ClientId = client.GetConn().Id req := protocol.(*pillx.TextProtocol) header.Cmd = 0x0DDC header.Error = 0x0000 header.Mark = 0xA8 header.Size = uint16(len(req.Content)) gatewayProtocol.Content = req.Content //发送给一个合适的worker worker := workers[worker_id] fmt.Printf("%x", gatewayProtocol.Header) fmt.Printf("%s", req.Content) worker.Send(gatewayProtocol) fmt.Printf("发送给worker %d\n", worker_id) }
func outerCloseHandler(client *pillx.Response, protocol pillx.IProtocol) { delete(clients, client.GetConn().Id) }