asp.net - Connection must be started before data can be sent. Call .start() before .send() -


i have following code call method on hub client page

var app = $.connection.myhub;     $.connection.hub.start().done(function () {                      $('#mylink').click(function (e) {                 e.preventdefault();                  app.server.mymethod();             });     ).fail(function (error) {             console.log('invocation of start failed. error: ' + error)         }); 

this code works fine after time passed, when click link again, following error

signalr: connection must started before data can sent. call .start() before .send() 
  1. the link click event inside start().done() if connection not started how event handler link click triggered.

  2. if because of connection timeout how can handle exception , redirect user login page.

  3. why code inside .fail() not execute

recommended reading: connection lifetime events in signalr

this theory whats happening. can confirm turning on client side logging - add $.connection.hub.logging = true; before start() call.

  1. and 3. connection started ok - this code works fine after time.... same reason, .fail() not executed.

but after connection established, there can short or longer disconnects. client trying reconnect time (disconnect timeout) , if not successful, it'll give , need call .start() again (in disconnected handler example).

  1. by handling 'disconnected' event

    $.connection.hub.disconnected(function() {});


Comments