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 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?