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:
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.
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.
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.
SignalR is an asynchronous signaling library for ASP.NET that our team is working on to help build real-time multi-user web application.
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:
Set ServicePointManager.DefaultConnectionLimit = 10;
at startup and that will give you 10 outbound connections to any host you're communicating with.
Use ServicePointManager.FindServicePoint(specificDomainUri).ConnectionLimit = 10
at startup and that will give you 10 outbound connections only to that specific IP/domain.
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With