I'm developing Twitter hashtag chats with events sent by the server with the https://github.com/antage/eventsource package
I have a problem disconnecting the client. I run the program to send messages to the client, but when the client disconnects, the program still works.
I do not know how to detect on the server side that the client is disconnected.
func (sh StreamHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { es := eventsource.New( &eventsource.Settings{ Timeout: 2 * time.Second, CloseOnTimeout: true, IdleTimeout: 2 * time.Second, Gzip: true, }, func(req *http.Request) [][]byte { return [][]byte{ []byte("X-Accel-Buffering: no"), []byte("Access-Control-Allow-Origin: *"), } }, ) es.ServeHTTP(resp, req) go func() { var id int for { id++ time.Sleep(1 * time.Second) es.SendEventMessage("blabla", "message", strconv.Itoa(id)) } }() }
source share