重新连接SignalR的最佳方法?

时间:2019-07-12 05:49:24

标签: c# asp.net-core signalr

我正在尝试连接到SignalR集线器。一切正常,但是下次登录(睡眠模式)后出现错误。

由于错误而断开连接

Error: Server timeout elapsed without receiving a message from the server.

Failed to complete negotiation with the server: Error

Failed to start the connection: Error

POST https://localhost:*****/hubname/negotiate net::ERR_NETWORK_CHANGED

在连接之前如何重新连接SignalR?

var connected = false
this.hubConnection.start()
            .then(function () {
                connected = true
            }).catch(function () {
                setTimeout(function () { obj.hubConnection.start() }, 5000) 
            })

        this.hubConnection.onclose(function () {
            connected = false
            if (!connected)
                setTimeout(function () { obj.hubConnection.start() }, 5000)
        })

0 个答案:

没有答案