You’ll clearly see the advantages of Web Socket over regular HTTP by monitoring network traffic with such tools as Wireshark and Google Chrome Developer Tools.
All the server-side functionality supporting this chapter is written in Java, using the Java API for Web Socket reference implementation, which is a part of the Java EE 7 specification.
Visualize a child sitting in the back seat of your car and asking every minute, "Have we arrived yet?
These options are hacks on top of a half-duplex (a one-way street) HTTP protocol to simulate real-time behavior. Some of the server’s responses will be empty if the requested data is not ready yet, as illustrated in Polling.For example, if you’re running an online auction and send a request to see the updated bids, you won’t receive any data back unless someone placed a new bid.If no one enters the elevator, it goes to the ground level and in 60 seconds goes up again. But if this elevator went up and waited until someone actually decided to go down (or got tired of waiting), we could call it a long polling mode. If you see an online auction that automatically modifies prices as people bid on items, it looks as if the server pushes the data to you.But the chances are, this functionality was implemented by using long polling, which is not a real server-side data push, but its emulation.A good illustration of such a server might be Facebook’s News Feed page.
A server can automatically update the client with new data without the client’s request.The server pushes the data to the client, pretending that the response never ends.For example, requesting a video from You Tube results in streaming data (frame after frame) without closing the HTTP connection.All modern browsers support the object, which can handle events arriving in the form of DOM events.This is not a request-response paradigm, but rather a unidirectional data push, from server to browser.Subscribing to server-sent events shows how a web browser can subscribe and listen to server-sent events.