func NewSimpleHTTPServer(port string, dir string) { if dir == "" { l.Fatal("No directory given, to serve") } http.Handle("/", http.FileServer(http.Dir(dir))) fmt.Println("Serving", dir, "at port", port) if err := http.ListenAndServe(":"+port, nil); err != nil { l.Fatal("error", err) } }
func (r *TCPRouter) setupClientCommChan(id string) *ProxyClient { port, ok := r.pool.GetAvailable() if !ok { l.Fatal("Coudn't get a port for client communication") } proxy, err := NewProxyClient(port) if err != nil { l.Fatal("Coulnd't setup client communication channel", err) } return proxy }
func (p *ProxyClient) Port() string { _, port, err := net.SplitHostPort(p.listenServer.Addr().String()) if err != nil { l.Fatal("couldn't get port for proxy client") } return port }
func main() { flag.Usage = Usage flag.Parse() if *port == "" || *backproxyAdd == "" || *externAddr == "" { flag.Usage() os.Exit(1) } // new clients go func() { backproxy, err := net.Listen("tcp", *backproxyAdd) if err != nil { l.Fatal("Client: Coundn't start server to connect clients", err) } for { adminc, err := backproxy.Accept() if err != nil { l.Fatal("Client: Problem accepting new client", err) } go setupClient(*externAddr, *port, adminc) } }() // new request server, err := net.Listen("tcp", net.JoinHostPort("0.0.0.0", *port)) if server == nil { l.Fatal("Request: cannot listen: %v", err) } l.Log("Listening at: %s", *port) for { conn, err := server.Accept() if err != nil { l.Fatal("Request: failed to accept new request: ", err) } go fwdRequest(conn) } }