go-socket.io icon indicating copy to clipboard operation
go-socket.io copied to clipboard

Why do I get "superfluous response.WriteHeader"?

Open viktoriia-starikova opened this issue 5 years ago • 11 comments
trafficstars

When connecting to the server I get an error:

2020/07/14 16:29:51 http: superfluous response.WriteHeader call from github.com/googollee/go-engine%2eio.(*Server).ServeHTTP (server.go:146)

Code on the server `package main import ( "fmt" "log" "net/http" "github.com/gorilla/mux" "github.com/gorilla/handlers"

socketio "github.com/googollee/go-socket.io"

)

func main() { fmt.Println("Hello world") router := mux.NewRouter() router.HandleFunc("/is-alive", isAlive).Methods("GET")

server, err := socketio.NewServer(nil)
if err != nil {
	log.Fatal(err)
}

server.OnConnect("/", func(s socketio.Conn) error {
	s.SetContext("")
	fmt.Println("connected:", s.ID())
	s.Emit("change")
	s.Join("bcast")
	return nil
})

server.OnEvent("/", "msg", func(s socketio.Conn, msg string) string {
	s.SetContext(msg)
	fmt.Println("event: msg")
	return "recv " + msg
})

server.OnError("/", func(s socketio.Conn, e error) {
	fmt.Println("meet error:", e)
})

server.OnDisconnect("/", func(s socketio.Conn, reason string) {
	fmt.Println("closed", reason)
})

go server.Serve()
defer server.Close()

router.Handle("/socket.io/", server)

log.Println("Serving at localhost:4444...")
log.Fatal(http.ListenAndServe(":4444", handlers.CORS(handlers.AllowedOrigins([]string{"*"}))(router)))

}

func isAlive(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) }`

viktoriia-starikova avatar Jul 14 '20 13:07 viktoriia-starikova

same issue. any resolution?

pratiknaik89 avatar Jan 18 '21 10:01 pratiknaik89

I got this same issue. too bad on my first try. very frustrating. any resolution?

ab185188 avatar Feb 12 '21 14:02 ab185188

me to ,have any resolution?

laoflch avatar Mar 13 '21 05:03 laoflch

me to

maglink avatar Apr 06 '21 09:04 maglink

me too!

smhmh avatar Apr 21 '21 05:04 smhmh

have any resolution?

actors315 avatar Jul 17 '21 04:07 actors315

I followed the examples provided and I get the same error - any advice?

cip8 avatar Aug 10 '22 13:08 cip8

Is there any fixes for this?

Poujhit avatar Jan 29 '23 14:01 Poujhit

any updates?

developerpaaji avatar Feb 17 '23 12:02 developerpaaji

Is there any fixes for this?

pdxrlj avatar Apr 17 '23 05:04 pdxrlj

While upgrading to version1.7 getting above error

mani3029 avatar Oct 18 '23 01:10 mani3029