Tuesday, August 26, 2014

ASP.NET SignalR

The official website of the project presents SignalR as:
“ASP.NET SignalR is a new library for ASP.NET developer that makes it incredibly simple to add real-time web functionality to your applications”

And Wiki says:
"SignalR is a server-side software system designed for writing scalable Internet applications, notably web servers. Programs are written on the server side in C#, using event-driven, asynchronous I/O to minimize overhead and maximize scalability."

Basically, SignalR isolates developer from low-level details, giving the impression of working on a permanently open persistent connection. To achieve this, SignalR includes components specific to both ends of communication, which will facilitate message delivery and reception in real time between the two. SignalR is in charge of determining which is the best technique available both at the client and at the server (Long Polling, Forever Frame, Websockets...) and uses it to create a underlying connection and keep it continuously open, also automatically managing disconnections and reconnections when necessary. SignalR provides a virtual persistent connection, and that everything works correctly in the backstage.

SignalR includes a set of transports or techniques to keep the underlying connection to the server open, and it determines which one it should use based on certain factors, such as the availability of the technology at both ends. SignalR will always try to use the most efficient transport, and will keep falling back until it finds one that is compatible with the context. This decision is made automatically during an initial stage in the communication between the client and the server, known as “negotiation”. It is also possible to force the use of a specific transport using the client libraries of the framework.

SignalR also includes a messaging bus capable of managing data transmission and reception between the server and the clients connected to the service. That is, the server is able to keep track of its clients and detect their connections and disconnections, and it will also have mechanisms to easily send messages to all clients connected or part of them, automatically managing all issues concerning communications (different speeds, latency, errors…) and ensuring the delivery of messages. Moreover, it includes powerful libraries on the client side that allow the consumption of services from virtually any kind of application, allowing us to manage our end of the virtual connection and send or receive data asynchronously.

In short, in SignalR provides rich platform to create multiuser real-time applications.

SignalR offers two different levels of abstraction above the transports used to maintain the connection with the server.

The first one, called Persistent connections, is the lower level, closer to the reality of the connections. In fact, it creates a development surface which is quite similar to programming with sockets, although here it is done on the virtual connection established by SignalR.
The second level of abstraction, based on components called Hubs, is quite further removed from the underlying connections and protocols, offering a very imperative programming model, where the boundaries traditionally separating the client and the server melt away.