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

SundaraPandian picture SundaraPandian · Oct 7, 2013 · Viewed 12.2k times · Source

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?

Answer

Matthieu Charbonnier picture Matthieu Charbonnier · Aug 4, 2017

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