小编Gui*_*meP的帖子

Eventsource golang:如何检测客户端断开连接?

我正在开发基于Twitter主题标签和服务器发送事件的聊天室,包含https://github.com/antage/eventsource

我有一个关于客户端断开的问题.我运行goroutine向客户端发送消息,但是当客户端断开连接时,goroutine仍然运行.

我不知道如何在服务器端检测到客户端已断开连接.

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))
        }
    }()

}
Run Code Online (Sandbox Code Playgroud)

go server-sent-events

9
推荐指数
3
解决办法
2384
查看次数

不支持所选的 SHA 变体

我正在使用 Ionic 开发移动应用程序,我必须与 Twitter API 连接。所以我使用 ng-cordova 和$cordovaAuth. 但是当我这样做时:

$cordovaOauth.twitter(clientId, clientSecret);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

错误错误:选上的SHA变体不以错误(天然的)在新的T(支持http://192.168.1.19:8100/lib/sha-js/sha1.js:12:276在Object.createSignature()的http:/ /192.168.1.19:8100/lib/ngCordova/dist/ng-cordova.js:6120:38 ) 在 Object.twitter ( http://192.168.1.19:8100/lib/ngCordova/dist/ng-cordova.js: 5623:55 ) 在 Object.initialize ( http://192.168.1.19:8100/js/services/twitter.js:18:18 )

所以,问题来自于sha1.js,我将它包含在我的index.html

如果你能帮助我就好了!

twitter twitter-oauth cordova ionic-framework ngcordova

5
推荐指数
1
解决办法
3430
查看次数