func (self *ConnectionManager) Loop(addr string) { fun := "ConnectionManager.Loop" tcpAddr, error := net.ResolveTCPAddr("tcp", addr) if error != nil { slog.Fatalf("%s Error: Could not resolve address %s", fun, error) panic("resolve address") } netListen, error := net.Listen(tcpAddr.Network(), tcpAddr.String()) if error != nil { slog.Fatalf("%s Error: Could not Listen %s", fun, error) panic("listen address") } defer netListen.Close() //go self.req() //go self.trans() for { slog.Infof("%s Waiting for clients", fun) connection, error := netListen.Accept() if error != nil { slog.Warnf("%s Client error: ", fun, error) } else { NewClient(self, connection) } } }
func StartHttp(cm *ConnectionManager, httpport string) { connman = cm go func() { http.HandleFunc("/push/", push) err := http.ListenAndServe(httpport, nil) //设置监听的端口 if err != nil { slog.Fatalf("StartHttp ListenAndServe: %s", err) panic("StartHttp ListenAndServe") } }() }