0

I have this code to test asynchronous programming in SignalR. this code send back to client the text after 10 seconds.

public class TestHub : Hub
{
    public async Task BroadcastMessage(string text)
    {
        await DelayResponse(text);
    }

    async Task DelayResponse(string text)
    {
        await Task.Delay(10000);
        Clients.All.displayText(text);
    }
}

this code work fine but there is an unexpected behavior. when 5 messages are sent in less than 10 second, client can't send more message until previous "DelayResponse" methods end. it happens per connection and if before 10 seconds close the connection and reopen it, client can send 5 messages again. I test it with chrome, firefox and IE. I made some mistake or it is signalr limitation?

ali afshari
  • 62
  • 1
  • 7

2 Answers2

1

You are most likely hitting a browser limit. When using longPolling and serverSentEvent transport each send is a separate HTTP request. Since you are delaying response these requests are longer running and browsers have limits of how many concurrent connection can be opened. Once you reach the limit a new connection will not be open until one of the previous ones is completed. More details on concurrent requests limit: Max parallel http connections in a browser?

Community
  • 1
  • 1
Pawel
  • 31,342
  • 4
  • 73
  • 104
  • that's exactly right. I work on windows 7 which doesn't support websocket so signalr transport type on my pc is "ServerSentEvents" so browser connection limitation reached. when I test my codes on windows 10 which supports websockets there was not any limitation. I sent about 500 message continuously and then got 500 responses after 10 seconds. – ali afshari Sep 28 '16 at 07:18
0

That's not the sens of signalR, that you waiting for a "long running" task. For that signalR supports server push mechanisme. So if you have something which needs more time you can trigger this from client. In the case the calculation is finish you can send a message from server to client.

Stephu
  • 3,236
  • 4
  • 21
  • 33