Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting several clients from the same host machine to signalr server blocks

As a part of a project in my education I am performance testing several .net real-time communication approaches. One of them is signalr. For this reason I have two programs:

  • ServerHostApp- A WPF application with a Microsoft.AspNet.SignalR.Hosting.Self.Server which exposes a single Hub.
  • ClientHostApp- A WPF application hosting many signalr clients

A typical workflow of the programs is: start up the server-> connect some number of clients with the ClientHostApp->run tests.

The programs work fine if they are both hosted on the same machine but if try to run the programs on different computers, problems appear. In particular, I am not able to connect more than one client from a single ClientHostApp instance.

Server code:

 //starting up the server
public override void Start()
{
  string url = "http://*:9523/MessagingServiceHostWPF/";
  Server = new SignalR.Hosting.Self.Server(url);
  Server.MapHubs();
  Server.Start();
}

. . .

//one of the methods inside the hub exposed by the server
    public DataContracts.ClientInfo AcknowledgeConnection(string handle)
    {
       ServerLogic.DataContracts.ClientInfo clientInfo = SignalRApplicationState.SingletonInstance.AddClient(handle, Context.ConnectionId);;
       return clientInfo;
     }

ClientHostApp:

//starting many clients in a loop
foreach (var client in _clients)
{
  client.Start();
}

. . .

//method inside the Client class
public async void Start()
{
  _hubConnection = new HubConnection(EndpointAddress);  
  _hubProxy = _hubConnection.CreateProxy("MessagingHub");

  await _hubConnection.Start().ContinueWith(task =>
    {
      _hubProxy.Invoke<ClientLogic.MyServices.ClientInfo>("AcknowledgeConnection", Handle).ContinueWith((t) =>
         {
              ClientInfo = t.Result;
              IsConnected = true;
         });  
     });
}

If I try to connect one client from the same ClientHostApp instance- I succeed. However, if I try connecting with 2 or more clients, the AcknowledgeConnection method on the Hub never gets executed, whereas the ClientHostApp program simply hangs without response. Strangely, if I start up Fiddler2 on my client machine, all the clients get connected and I can run my tests.

Do you know what I am missing here? Thanks.

like image 999
reederz Avatar asked Dec 06 '12 21:12

reederz


People also ask

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.

What is hub proxy SignalR?

The SignalR Hubs API enables you to make remote procedure calls (RPCs) from a server to connected clients and from clients to the server. In server code, you define methods that can be called by clients, and you call methods that run on the client.

Is SignalR asynchronous?

SignalR is an asynchronous signaling library for ASP.NET that our team is working on to help build real-time multi-user web application.


1 Answers

I'm going to guess you're running into the default network connection limit per host in your client app. It doesn't apply to localhost, so that's most likely why you're only experiencing it when you run across multiple machines. You have some options for how you can solve:

Code Based

Increase for all hosts

Set ServicePointManager.DefaultConnectionLimit = 10; at startup and that will give you 10 outbound connections to any host you're communicating with.

Increase for a specific host

Use ServicePointManager.FindServicePoint(specificDomainUri).ConnectionLimit = 10 at startup and that will give you 10 outbound connections only to that specific IP/domain.

Config Based

Increase for all hosts

Configure the following to increase to 10 outbound connections to any host you're communicating with:

 <system.net>
     <connectionManagement>
         <add name="*" maxconnection="10" />
     </connectionManagement>
 </system.net>

Increase for specific host

Configure the following to increase to 10 outbound connections only to a specific IP/domain:

 <system.net>
     <connectionManagement>
         <add name="somesubdomain.somedomain.com" maxconnection="10" />
     </connectionManagement>
 </system.net>
like image 195
Drew Marsh Avatar answered Oct 28 '22 04:10

Drew Marsh