Signalr - endless $.connection.hub.disconnected event?

Royi Namir

I'm using Signalr 2.2.1 with a successful websocket connection.

enter image description here

Here are the events for different states : ( simplified for brevity)

var hub = $.connection.moveShapeHub;


$.connection.hub.start().done(function ()
{
    console.log("hub started successfully");

}).fail(function () { console.log('Could not Connect!'); });


$.connection.hub.disconnected(function ()
{
    $.connection.hub.start();
    console.log('Connection disconnected')
});

My app is working fine as expected.

But look what happen when I disable the network card ( I access my computer not via localhost but via dynamic dns which goes to the world and then comes back to my computer)

At first you can see websocket connection error (I see it multiple times)

WebSocket connection to 'ws://xxxxxx.ddns.net/signalr/reconnect?transport=webSockets&messageId=d-C68A95E5-g%2C1&clientProtocol=1.5&connectionToken=%2FDJL8eAtVtSA3XKeap4Js3IrbkCm56C%2FWKCQtApGiMroWAgnzNoRHmJ0Y2LpIdWWWL%2BfY3dXvJqYHFfby1XYii0ibPpKM55PQuZyf9aH4k9JHIT79lWoMWBasIpa9Gjk&connectionData=%5B%5D&tid=2' failed: Error in connection establishment: net::ERR_INTERNET_DISCONNECTED

And then you see endless calls(!!!) to the negotiate

http://xxxx.ddns.net/signalr/negotiate?clientProtocol=1.5&connectionToken=%2FDJL8eAtVtSA3XKeap4Js3IrbkCm56C%2FWKCQtApGiMroWAgnzNoRHmJ0Y2LpIdWWWL%2BfY3dXvJqYHFfby1XYii0ibPpKM55PQuZyf9aH4k9JHIT79lWoMWBasIpa9Gjk&connectionData=%5B%7B%22name%22%3A%22moveshapehub%22%7D%5D&_=1485811277855

Wait ~15 seconds to see the endless loop :

enter image description here

Question

How can I fix those endless calls ? Or alternatvly - increase delay in those "negotiate calls" -say every 2 seconds ( instead of blazing fast endlessly 0.1 seconds)

Edit

I've changed this code :

$.connection.hub.disconnected(function ()
    {
        $.connection.hub.start();
        console.log('Connection disconnected')
    });

to this (remove hub start):

$.connection.hub.disconnected(function ()
    {
             console.log('Connection disconnected')
    });

And now I see only this message :

enter image description here

But now I'm losing all the basic idea of "trying restart connecting" in case of disconnect. So I ask again is there any reasonable solution or at least trying "restart the connection every 2 seconds" ?

Pawel

negotiate is the first request a SignalR client sends to establish a connection. You are trying to start the connection as soon as it gets disconnected in the disconnected event handler. Because the network is down negotiate fails and the disconnected event is invoked and you try to start the connection again. The documentation shows how to do it with the timeout:

$.connection.hub.disconnected(function() {
   setTimeout(function() {
       $.connection.hub.start();
   }, 5000); // Restart connection after 5 seconds.
});

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Signalr-無限の$ .connection.hub.disconnectedイベント?

分類Dev

Retrieve Service Bus event hub connection string

分類Dev

SignalR objects are not being deleted from the heap even when the hub connection is disposed

分類Dev

SignalR Get Connection Id

分類Dev

Access SignalR Hub without Constructor Injection

分類Dev

How to call SignalR hub when application start?

分類Dev

Azure Event Hub Python SDK

分類Dev

Detect lost connection from SignalR Core connection

分類Dev

Cannot connect bot to Bale messenger API: network connection disconnected

分類Dev

Can I run SignalR hub through Azure API Management?

分類Dev

SignalR: Generated proxy vs. dynamically created hub file

分類Dev

About checkpoint strategy in event hub processor

分類Dev

Unable to ingest JSON data into Azure Event Hub

分類Dev

Cant create Event Hub in Brazil South Region

分類Dev

SignalR - Possible Values for Transport Method for a Connection on Client

分類Dev

SignalR client-server connection issue

分類Dev

MirrorMaker Kafka 0.9 connection to Kafka Brokers 0.10 (IBM Message Hub)

分類Dev

$ .connection.hub.start()。done()のエラー500

分類Dev

Bluedroid AV 接続が失敗する (BTAV_CONNECTION_STATE_DISCONNECTED 状態)

分類Dev

Azure Streaming Analytics job not connecting to Event Hub input

分類Dev

Azure Event Hub firewall does empty settings allow everything to connect

分類Dev

Equivalente de tema de Apache Kafka en Azure Event Hub

分類Dev

ControllerからSignalR Core Hubメソッドを呼び出す

分類Dev

Is there a way to connect to SignalR Hub built in ASP. NET from other application?

分類Dev

Is calling a SignalR Hub from the Application Service Layer a bad practice in ASP.Net Boilerplate?

分類Dev

Access SignalR Hub Context.Items from an singleton service in ASP.NET Core

分類Dev

SignalR Hub in App_Code causes "Two Hubs must not share the same name" error

分類Dev

Azure MobileAppsのSignalR.HubでMobileAppSettingsDictionaryを取得する方法

分類Dev

SignalRのhub.serverでClassを切り替える方法は?

Related 関連記事

  1. 1

    Signalr-無限の$ .connection.hub.disconnectedイベント?

  2. 2

    Retrieve Service Bus event hub connection string

  3. 3

    SignalR objects are not being deleted from the heap even when the hub connection is disposed

  4. 4

    SignalR Get Connection Id

  5. 5

    Access SignalR Hub without Constructor Injection

  6. 6

    How to call SignalR hub when application start?

  7. 7

    Azure Event Hub Python SDK

  8. 8

    Detect lost connection from SignalR Core connection

  9. 9

    Cannot connect bot to Bale messenger API: network connection disconnected

  10. 10

    Can I run SignalR hub through Azure API Management?

  11. 11

    SignalR: Generated proxy vs. dynamically created hub file

  12. 12

    About checkpoint strategy in event hub processor

  13. 13

    Unable to ingest JSON data into Azure Event Hub

  14. 14

    Cant create Event Hub in Brazil South Region

  15. 15

    SignalR - Possible Values for Transport Method for a Connection on Client

  16. 16

    SignalR client-server connection issue

  17. 17

    MirrorMaker Kafka 0.9 connection to Kafka Brokers 0.10 (IBM Message Hub)

  18. 18

    $ .connection.hub.start()。done()のエラー500

  19. 19

    Bluedroid AV 接続が失敗する (BTAV_CONNECTION_STATE_DISCONNECTED 状態)

  20. 20

    Azure Streaming Analytics job not connecting to Event Hub input

  21. 21

    Azure Event Hub firewall does empty settings allow everything to connect

  22. 22

    Equivalente de tema de Apache Kafka en Azure Event Hub

  23. 23

    ControllerからSignalR Core Hubメソッドを呼び出す

  24. 24

    Is there a way to connect to SignalR Hub built in ASP. NET from other application?

  25. 25

    Is calling a SignalR Hub from the Application Service Layer a bad practice in ASP.Net Boilerplate?

  26. 26

    Access SignalR Hub Context.Items from an singleton service in ASP.NET Core

  27. 27

    SignalR Hub in App_Code causes "Two Hubs must not share the same name" error

  28. 28

    Azure MobileAppsのSignalR.HubでMobileAppSettingsDictionaryを取得する方法

  29. 29

    SignalRのhub.serverでClassを切り替える方法は?

ホットタグ

アーカイブ