Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between web sockets, long polling, server-sent events and forever frame?

I'm currently exploring SignalR, this technology supports transports (web wockets, long polling ,server-sent events and forever frame).

I have understood the terminology web sockets and long polling. But what is Server-Sent Events and Forever Frame?

How all four differ from each other?

like image 545
SundaraPandian Avatar asked Oct 07 '13 13:10

SundaraPandian


People also ask

What are the differences between long polling WebSockets and server-sent events?

Long-polling opens an HTTP request and remains open until an update is received. Upon receiving an update, a new request is immediately opened awaiting the next update. Server-sent events(SSE) rely on a long-lived HTTP connection, where updates are continuously sent to the client.

What is the difference between WebSocket and long polling?

WebSockets are Full-Duplex meaning both the client and the server can send and receive messages across the channel. Long Polling is Half-Duplex meaning that a new request-response cycle is required each time the client wants to communicate something to the server.

What is the difference between server-sent events SSEs and WebSockets in html5?

Obviously, the major difference between WebSockets and Server-Sent Events is that WebSockets are bidirectional (allowing communication between the client and the server) while SSEs are mono-directional (only allowing the client to receive data from the server).

What is forever frame?

In Forever frame, first the client receives the page including an iframe tag, establishing a long-lived connection inside the hidden iframe. And then the client receives chunked datas from the server and manipulates the DOM with some functions on the first document the client already has.


1 Answers

Transports and fallbacks of SignalR:

WebSocket Full-duplex

Websocket is a full-duplex communication channels over a single TCP connection. When both server and browser support, it is the only transport that establishes a true persistent, two-way connection between client and server.

Server Sent Events Simplex

also known as EventSource is a technology where a browser receives automatic updates from a server via HTTP connection. The Server-Sent Events EventSource API is standardized as part of HTML5 by the W3C.

Forever Frame One request -> One infinite response

Forever Frame creates a hidden IFrame which makes a request to an endpoint on the server that does not complete. The server then continually sends script to the client which is immediately executed, providing a one-way realtime connection from server to client. The connection from client to server uses a separate connection from the server to client connection, and like a standard HTTP request, a new connection is created for each piece of data that needs to be sent.

Ajax long polling (One Request -> One Response [but delayed]) repeated

Long polling does not create a persistent connection, but instead polls the server with a request that stays open until the server responds, at which point the connection closes, and a new connection is requested immediately. This may introduce some latency while the connection resets.

More info:

https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/introduction-to-signalr https://en.wikipedia.org/wiki/Server-sent_events

like image 86
Matthieu Charbonnier Avatar answered Nov 08 '22 13:11

Matthieu Charbonnier