douzhi1924 2018-10-10 11:26
浏览 145

我应该在Golang http.server中配置什么来处理SSE

http.server can be configure with these parameters:

ReadTimeout, WriteTimeout,IdleTimeout and others

I was just playing with parameters to see in which cases would be better to configure with SSE, so following the same structured from here I just add some prints to see when the clients conects and when disconects, like:

 ....
    notify := rw.(http.CloseNotifier).CloseNotify()
     fmt.Fprintf(w, "data: .

") `//I add this because [onopen][3] won´t` fire if nothing is sent when start conecting
    fmt.Println(" conecting")
        for {
            select {
            case <-notify:
    fmt.Println("closing")
                return
            default:

                // Write to the ResponseWriter
                // Server Sent Events compatible
                fmt.Fprintf(rw, "data: %s

", <-messageChan)

                // Flush the data immediatly instead of buffering it for later.
                flusher.Flush()
            }
        } 

So the only value that if I changed, it prints "closing" is WriteTimeout but reading this article it is confuse to me this part:

Finally, Go 1.8 introduces IdleTimeout which limits server-side the amount of time a Keep-Alive connection will be kept idle before being reused

But as I said even if I change IdleTimeout the client won't close, is it because the first time the client conects I write to it, or is it a bug? Which of three should I change then? Go version: 1.11.1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!