Chapter 5. Real-Time Data and WebSockets

In this chapter, we will show you how to enable real-time data communication using WebSockets. This will allow your server to directly communicate with the connected clients without having any polling on the client side.

I would really love a two-way conversation, John

In its infancy, the Internet was not much of a two-way street. The traditional client-server architecture was the king, and servers initiating communication with clients was almost unheard of (and quite possibly seen as quite heretical by some, too).

However, starting with protocols such as Internet Relay Chat (IRC), real-time chat applications quickly became killer apps over time, with an enormous surge in popularity among ordinary users (if you are old enough to remember the instant messaging computer program (ICQ), yes, that is nostalgia that you are feeling). It was not very long until real-time features took the leap to the HTTP world, causing browser-based chat services to pop up everywhere. Meanwhile, related concepts such as push notifications gained popularity, especially with the advent of the smartphone.

Polling

Today, real-time features are an integral part of the Internet as we know it. However, their implementation has not always been optimal. Especially during its early stages, real-time data communication was almost always implemented by using polling, a technique where the client regularly contacts the server in order to check whether its state has changed. If it had (say, if a new message had been made available), the server responded by sending the updated state back. Needless to say, polling is a recipe for wasted resource usage. Moreover, it leads to rather choppy programming, since we find ourselves just repeatedly asking for updates rather than waiting and taking action on them when they are actually sent.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.156.251