func main() { workers = make(map[uint32]*pillx.Response) clients = make(map[uint64]*pillx.Response) chat_channel = pillx.NewChannel("chat") innerServer := &pillx.Server{ Addr: ":10086", Handler: nil, Protocol: &pillx.GateWayProtocol{}, } innerServer.HandleFunc(pillx.SYS_ON_CONNECT, innerConnectHandler) innerServer.HandleFunc(pillx.SYS_ON_MESSAGE, innerMessageHandler) innerServer.HandleFunc(pillx.SYS_ON_CLOSE, innerCloseHandler) fmt.Println("内部通信服务启动") go innerServer.ListenAndServe() outerServer := &pillx.Server{ Addr: ":8080", Handler: nil, Protocol: &pillx.TextProtocol{}, } outerServer.HandleFunc(pillx.SYS_ON_CONNECT, outerConnectHandler) outerServer.HandleFunc(pillx.SYS_ON_MESSAGE, outerMessageHandler) outerServer.HandleFunc(pillx.SYS_ON_CLOSE, outerCloseHandler) fmt.Println("外部通信网关服务启动") outerServer.ListenAndServe() }
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) }