title: SignalR connection lost when android device sleeps
body: <p>I have an MVC 4 application with SignalR connected to many Android tablets simultaneously. When the devices go to sleep, some of the connections are lost and some are maintained, seemingly with no pattern.</p>
  
  <p>I have the following code on the view to attempt to restart the connection upon disconnect:</p>
  
  <pre><code>    $.connection.hub.disconnected( function () {
          setTimeout( function () {
              $.connection.hub.start();
          }, 5000);
      });
  </code></pre>
  
  <p>I also have the following lines in the Application_Start() method:</p>
  
  <pre><code>    GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromHours( 6 );
      GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromHours( 6 );
  </code></pre>
  
  <p>I understand that 6 hours is excessive, this was simply done to try to ensure that the connection would never timeout during testing.</p>
  
  <p>I also have the tablets set to maintain Wi-Fi connection during sleep.</p>
  
  <p>However, when the tablets are put to sleep, then awoken just a few minutes later, some connections will still be active, while others will not.</p>
  
  <p>How can I ensure that the SignalR connection will either be maintained or restarted when the devices come back from sleep?</p>