Programming - WebSocket, an Introduction
Hello, I'm going to show you what is WebSocket and how to create a simple online chat with it.
First, what is WebSocket?
Simplifying a WebSocket is the way to create a persistent connection between the client and the server, where the client can at any time submit data to the server and the server can at any time send data to the client, even if the client doesn't request it.
Or in a more technical way "WebSockets provide a bidirectional, full-duplex communications channel that operates over HTTP through a single TCP/IP socket connection"
But if you don't know much about clients and servers in the web world you now would be thinking, ok, but what this is used for?
Well with this you can create a communication much more efficient between client and server.
But before I explain why, let's see how the internet worked when it was created.
In the beginning, the internet was good because you could access an URL and receive a "website", that was basically a book but digital, this was pretty good, but then the users started to want to interact with the page more and more, they weren't satisfied with only reading things, this is called Web 1.0 and can only serve static data.
Later, when the technologies were becoming better and better it was born the first dynamic website, or what you would call a blog, in this type of website the creator could add things dynamically easier, and now the user could communicate with the server, so comments were added into blogs, and so on, this is called Web 2.0 and can serve both static data and dynamic data.
But now, again the people aren't satisfied with only reading and interacting with the creator, they want to interact more and in a real-time form, because before if you wanted to create an online chat you would need that the client creates requests after 1 or 5 minutes asking the server: Is there any new messages? while this can sound little because in a day it would only be around 1440 or 288 requests, if there are 1000 users, well, you can already understand what would happen, but 1000 can still be considered little, Whatsapp at the time of this post has around 2 billion users, so you would receive billions of request per day, even if no one submit a message.
To "correct" this, it was needed to a new technology to be born, so WebSocket was created, on WebSocket, the client doesn't need to request the messages, only submit it, and the server would verify for who this message is, and then the server would submit the message to the client, at the time this was created, it was a huge revolution because before only the client could communicate with the server at any moment, the server could only respond the client, now the server can also communicate with the client.
This is the basics you need to know to understand a little about WebSocket and its revolution, if you want to know more, you can read this link.

Comments
Post a Comment