How SignalR works internally?

No, SignalR is an abstraction over a connection. It gives you two programming models over that connection (hubs and persistent connections). SignalR has a concept of transports, each transport decides how data is sent/received and how it connects and disconnects.

SignalR has a few built in transports:

  1. WebSockets
  2. Server Sent Events
  3. Forever Frame
  4. Long polling

SignalR tries to choose the “best” connection supported by server and client (you can also force it to use a specific transport).

That’s the high level. If you want to see how each transport is implemented, you can look at the source code.

There’s also client code for each transport:
https://github.com/SignalR/SignalR/tree/master/src/Microsoft.AspNet.SignalR.Client.JS

If you’re asking about how the long polling transport works in particular:

It sends an ajax request to the server that’s waiting asynchronously for a signal to respond. When there is a signal or the request times out, it returns from the server and sends another request and the process continues. (I left some details out about how the client it keeps track of what it saw so it doesn’t miss messages)

Hopefully that answers most of your question.

Leave a Comment