I have a scenario where server need to close the http connection with client upon receiving an internal event(eventIsSet is false). When the eventIsSet is true, I want to reopen the connection and start listening on same port.
Here is the snippet of code that I was trying server := &http.Server{} listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: ipAddr, Port: port}) if err != nil { stdLogObj.Error("Error creating listener") return } var connection bool for { if eventIsSet { if connection == false { server.Serve(listener) connection = true } }else{ fmt.Println("Pacman or db connection went down so stopped to listen on webservice port") if connection == true { listener.Close() connection = false } } } Was trying to use listener.Close() but understood that it stops the server listen on port but still serve via connections which are open. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.