Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR client with multiple connections

I have multiple SignalR 'services' running and only one UI to access them.

How can I make the client js to talk to multiple connections with different Url? Because it seems I can only specify one url per $.connection.hub, and I can't use multiple 'signalr/hubs' client scripts.

Any help? Thanks.

like image 453
Adamy Avatar asked Mar 18 '13 01:03

Adamy


People also ask

How many connections can SignalR handle?

In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).

Is SignalR full duplex?

SignalR supports full duplex communication that allows the client and server to transfer data back and forth.

How do I send client specific messages using SignalR?

We change the BroadcastChartData() method to accept connectionId as an additional parameter. This way, we can find the client using the connectionId and send a message just to that client. Additionally, we add a new GetConnectionId() method, which returns the connectionId of the client.


1 Answers

$.connection.hub is created in the /signalr/hubs inclusion.

At the end of the file it essentially does:

$.connection.hub = $.hubConnection("/signalr", { useDefaultPath: false });

To create the hub proxy you do:

var myHub = $.connection.hub.createHubProxy('myHub');

Simple example for multiple connections:

var connection1 = $.hubConnection("http://www.myfirstendpoint.com");
var connection2 = $.hubConnection("http://www.mysecondendpoint.com");

var myCon1Hub = connection1.createHubProxy('myCon1Hub');
var myCon2Hub = connection2.createHubProxy('myCon2Hub');

myCon1Hub.client.foo = function() { ... Whatever you want ... };
myCon2Hub.client.foo = function() { ... Whatever you want ... };

connection1.start();
connection2.start();
like image 64
N. Taylor Mullen Avatar answered Oct 24 '22 05:10

N. Taylor Mullen