title: Signalr - endless $.connection.hub.disconnected event?
body: <p>I'm using Signalr 2.2.1 with a successful websocket connection.</p>
  
  <p><a href="https://i.stack.imgur.com/QDh1n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QDh1n.png" alt="enter image description here"></a></p>
  
  <p>Here are the events for different states : ( simplified for brevity)</p>
  
  <pre><code>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')
  });
  </code></pre>
  
  <p>My app is working fine as expected.</p>
  
  <p>But look what happen  when I <em>disable</em> the network card <em>( I access my computer not via localhost but via dynamic dns which goes to the world and then comes back to my computer)</em></p>
  
  <p>At first you can see websocket connection error (I see it multiple times)</p>
  
  <blockquote>
    <p>WebSocket connection to
    'ws://xxxxxx.ddns.net/signalr/reconnect?transport=webSockets&amp;messageId=d-C68A95E5-g%2C1&amp;clientProtocol=1.5&amp;connectionToken=%2FDJL8eAtVtSA3XKeap4Js3IrbkCm56C%2FWKCQtApGiMroWAgnzNoRHmJ0Y2LpIdWWWL%2BfY3dXvJqYHFfby1XYii0ibPpKM55PQuZyf9aH4k9JHIT79lWoMWBasIpa9Gjk&amp;connectionData=%5B%5D&amp;tid=2'
    f<strong>ailed: Error in connection establishment:
    net::ERR_INTERNET_DISCONNECTED</strong></p>
  </blockquote>
  
  <p>And then you see <strong>endless calls</strong>(!!!) to the negotiate</p>
  
  <blockquote>
    <p><a href="http://xxxx.ddns.net/signalr/negotiate?clientProtocol=1.5&amp;connectionToken=%2FDJL8eAtVtSA3XKeap4Js3IrbkCm56C%2FWKCQtApGiMroWAgnzNoRHmJ0Y2LpIdWWWL%2BfY3dXvJqYHFfby1XYii0ibPpKM55PQuZyf9aH4k9JHIT79lWoMWBasIpa9Gjk&amp;connectionData=%5B%7B%22name%22%3A%22moveshapehub%22%7D%5D&amp;_=1485811277855" rel="nofollow noreferrer">http://xxxx.ddns.net/signalr/negotiate?clientProtocol=1.5&amp;connectionToken=%2FDJL8eAtVtSA3XKeap4Js3IrbkCm56C%2FWKCQtApGiMroWAgnzNoRHmJ0Y2LpIdWWWL%2BfY3dXvJqYHFfby1XYii0ibPpKM55PQuZyf9aH4k9JHIT79lWoMWBasIpa9Gjk&amp;connectionData=%5B%7B%22name%22%3A%22moveshapehub%22%7D%5D&amp;_=1485811277855</a></p>
  </blockquote>
  
  <p>Wait <strong>~15</strong> seconds to see the endless loop : </p>
  
  <p><a href="https://i.stack.imgur.com/9rJnk.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9rJnk.gif" alt="enter image description here"></a></p>
  
  <p><strong>Question</strong></p>
  
  <p>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)</p>
  
  <p><strong>Edit</strong> </p>
  
  <p>I've changed this code : </p>
  
  <pre><code>$.connection.hub.disconnected(function ()
      {
          $.connection.hub.start();
          console.log('Connection disconnected')
      });
  </code></pre>
  
  <p>to this  (remove hub start):</p>
  
  <pre><code>$.connection.hub.disconnected(function ()
      {
               console.log('Connection disconnected')
      });
  </code></pre>
  
  <p>And now I see only this message : </p>
  
  <p><a href="https://i.stack.imgur.com/V6I9w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V6I9w.png" alt="enter image description here"></a></p>
  
  <p>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" ?</p>