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 helloHandler(client *pillx.Response, protocol pillx.IProtocol) { fmt.Println("test3") req := protocol.(*pillx.GateWayProtocol) fmt.Printf("%x", req.Header) fmt.Printf("%s", req.Content) req.Content = []byte("user" + strconv.FormatUint(req.Header.ClientId, 10) + ": " + string(req.Content) + "\r\n") req.Header.Size = uint16(len(req.Content)) client.Send(req) }
func helloHandler(client *pillx.Response, req pillx.IProtocol) { //fmt.Print(string(req.Content)) // client.Send(req) //io.WriteString(client, "World") channel := pillx.NewChannel("all") channel.Subscribe(client) channel.Publish(req) }
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) }