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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作