SignalR call method: the connection must be started before sending data

There is a lot of “connection that needs to be started before data can be sent” here and on GitHub, but I hardly see any problems with hubs.

$(function () { // Declare a proxy to reference the hub. var connection = $.hubConnection('http://www.website.net/'); var chat = connection.createHubProxy('MyHub'); // Start the connection. $.connection.hub.start().done(function () { console.log('Connect! connection Id=' + $.connection.hub.id); $('#sendmessage').click(function () { chat.invoke('method1','0000').done(function () { console.log ('Invocation of method1 succeeded'); }).fail(function (error) { console.log('Invocation of method1 failed. Error: ' + error); }); }); }) .fail(function(){ console.log('Could not Connect!'); }); }); 

The above code makes it possible to execute the method when the user clicks a button. I can check if this method works with my WPF.NET application.

I can get the connection identifier successfully, but when I click the button, it says “SignalR call method: the connection must be started before sending data. Call .start () before the .send () error.

What did I misunderstand?

+7
javascript signalr
source share
1 answer

Read the tutorial carefully, and now it works.

  $(function () { // Declare a proxy to reference the hub. var connection = $.hubConnection('http://www.website.net/'); var chat = connection.createHubProxy('MyHub'); connection.start().done(function() { console.log('Now connected, connection ID=' + connection.id); // Wire up Send button to call sendmessage on the server. $('#sendmessage').click(function () { chat.invoke('method1', '0000'); }); }) .fail(function(){ console.log('Could not connect'); });; }); 
+7
source share

All Articles