What are the possible cases of using a persistent connection?

5

I've been reading about SignalR for the past few days and I've basically realized that one of its key features is to maintain a persistent connection of the server to the possible clients by accessing the server. Basically, it allows us to create Hubs and then allow several clients (which can be both Web and .NET applications) to connect to these Hubs and there is a kind of continuous connection.

I've been working with web programming since 2009 and this is quite different from the traditional approach using stateless HTTP. In these cases everything is based on requisitions and answers. The client makes a request, the request is processed in a pipeline on the server, the server returns a response and when the response arrives on the client the connection to the server is over. Even in single page applications the logic is this, except that the server starts serving a RESTful API.

Being accustomed to this approach I can not see what the utilities are, the real cases of using a persistent connection. This seems to be a very useful thing, but in what cases is this really relevant and does it make sense to use?

I always see the same example of chat, which has several clients connected and they need to receive messages from others in real time. Okay, it's a valid example, but the only use case for this kind of technology is to send messages from the server to the client without relying on the client p>     

asked by anonymous 06.07.2014 / 01:18

2 answers

2

Think of a site where people post questions and answers, comment, and do other things. Think people will want to know when you have a change in the list of questions, when someone modifies something of your interest, communicates directly with the person, or when someone votes and their reputation changes, when there is a moderation queue to review. p>

This is an example of site that would benefit from a persistent connection.

But do not stick to a concrete example. Understand why the persistent connection is useful.

When you use REST the application is explicitly requesting information from the server. The user in one way or another determined what and when will ask something for the server.

Websockets are useful when you want the opposite, whether the server communicates with the client. Let him determine what and when to send some information to the client. No matter what it is:

  • chat
  • interaction networks between people (social, technical or other)
  • games
  • miscellaneous monitoring (equipment, financial market, miscellaneous news feed, etc.)
  • collaboration between work or study team members
  • Real-time usage flow of site by users
  • update based on external data (GPS for example), etc.

In addition, communication can be more efficient if used properly. This way you only travel what is really needed, only the data that has changed.

One last reason I can remember is when you're interacting with something that only provides this API.

It is interesting to have a ping mechanism to close a connection through the server to keep connections open when they are not active. It is common for the client not to close the connection. There are several techniques for doing forced closure, but that's another matter.

    
22.12.2014 / 14:45
1

This is exactly the same point that Client-Server developers, accustomed to with permanent connections, got up to when dynamic web applications started to become popular using frameworks such as CGI, WebBase ASP and the like.

'We can do everything with a permanent connection. What is the benefit of adding all this new overhead ? '

The interesting thing is that many of the points defended in the distant past can be used to justify the use of SignalR and the like:

  • You save the process of all handshaking required to establish a connection;
    • Especially important if you are running under HTTPS / TLS / SSL (which is why several secure applications request Keep-Alive );
    • Fewer handshaking means shorter response times;
    • Least amount of data trafficked;
    • More responsive application.

In summary, persistent connections benefit any application that requires a large amount of data to maintain its transactional state or that needs to minimize server-to-client latency.

    
09.07.2014 / 17:20