I’m trying to implement a client for comet protocol.
In “streaming” mode the server returns all results on single http channel using chunked transfert.
With the following code, I can receive the first response from the commands that creates the server, but nothing else. The other following messages are lost.
p := make([]byte, 50)
rd := bufio.NewReader(body)
for {
l, err := rd.Read(p)
if err != nil {
log.Fatal("Read Error:", err)
return
}
fmt.Println(l, string(p))
}
And after 1 minute the error message:
2019/09/24 17:37:13 Read Error:unexpected EOF
exit status 1
Looks like the channel is closed after the first response.
Any idea?
Hi,
I am not familiar with Comet, but it looks like you want to implement Server-Sent Events. Most modern browsers support SSE streams and there are libraries for it.
Thanks for the suggestion. Yes I believe the principle is similar.
I’ve tried to grab the reader code from https://github.com/r3labs/sse, and the result is the same: “Read Error:unexpected EOF” Whatever reader or method I use, I received the same error when the 2nd message is sent. So I believe my issue is in lower level.