SignalR
Last updated
Last updated
SignalR provides the consistent or persistent connection between the server and the client.
It is used to develop real-time applications.
it bridges the gap between the server and the client so the information can flow in and out in real-time without any restriction or barrier.
it is bi-directional meaning server can send data to the client and vice versa.
Eg. Chat Applications, Social Applications.
SignalR uses only one of the four components / technologies.
Web sockets
->
Event Source
->
Forever Frame
->
Long Polling
First it goes to Web Sockets if not available then Event Source and so on as it goes further towards the end the communication efficiency between server and client decreases.
implementing SignalR means getting all the 4 components in a single package.
if any of the 4 components gets any updates, SignalR is gonna handle those and make the application work as it was expected to do.
SignalR is an abstraction means we don't have to go into details how it works.
it is cross-application compatible and easy to use.
it can be used to make broadcast groups.
scalable
AJAX
AJAX provides the server validation and it can also check for the new data.
It is not an open/persistent connection .
AJAX requests the server for the new data if it got any and keep on requesting.
While Long Polling will request the server once for any new data that the client request, the server will keep the request as soon as it gets the data it will respond.
Disadvantage
simulates the persistent connection
one way means server cannot act on its own behind there is always request from client
it uses IFrame
server pushes the data to the client
Disadvantages
high memory usage
client should support IFrames
one-way persistent connection means from server to client.
it uses content-type (text/event-stream)
one-way persistent connection means server to client
asynchronous
think of it as subscribe option when you subscribe to the channel you get the updates not the another way around
bi-directional persistent connection
multiuser
full -duplex - communication between server and client can happen at the same time
asynchronous
inherits the Hub class
RPC (Remote Procedure Call)
server can call the functions at client side and vice versa
Hubs vs Persistent Connections
Hubs are at higher level than Persistent Connections
both of these are classes which can be inherited
Persistent Connection get instantized when connection is established and stays persistent until connection is closed. While Hubs are instantized for every new request.