Real Time Web with WebSockets
Internet Communication Basics
Clients and Servers
Every time you use the internet, you're part of a global conversation. This conversation happens between two main players: clients and servers.
A client is the device you're using, like your phone or laptop, along with the software on it, such as a web browser. It's the one asking for information. A server is a powerful computer that stores website files, data, and applications. Its job is to listen for requests and serve up the information it holds.
Think of it like a library. You (the client) walk in and ask the librarian for a specific book. The library (the server) finds that book on its shelves and hands it to you. The client asks, and the server provides.
The Request-Response Cycle
This digital conversation follows a strict set of rules called the Request-Response model. It's a simple, turn-based process. The client always speaks first by sending a request for something, like a webpage, an image, or a video. The server then processes this request and sends the information back in a response.
It’s like ordering a pizza. You call the shop (the request) and ask for a large pepperoni. You then wait. The pizza shop makes your pizza and delivers it to your door (the response). The key thing is, the pizza shop would never just send you a pizza without you asking for it first. The customer has to initiate.
In this model, the client always initiates the conversation. A server can't send data unless a client has specifically requested it.
This works great for most of what we do online. You click a link (request), and a new page loads (response). You search for something (request), and you get a list of results (response). Each action is a new, separate conversation.
A Digital Postal Service
So how does the data actually travel from the server to your client? It doesn't move in one giant, continuous stream. Instead, it's broken down into thousands of tiny pieces called packets.
Think of the internet as a massive, global postal service. If you wanted to send a book to a friend, you wouldn't mail the whole book in one enormous envelope. Instead, you'd tear out each page, put each page in a separate, small envelope, and mail them all individually. Each small envelope would have your friend's address (the destination) and your address (the sender).
The postal service (the internet) then sends these envelopes on their way. They might take different routes, but they all eventually arrive at your friend's house. Your friend then reassembles the pages in the correct order to read the book. Breaking data into packets makes the transfer of information across the internet manageable and efficient.
This brings us to a crucial characteristic of this system: it's stateless. The word sounds technical, but the idea is simple. When a server sends a response, it immediately forgets about the client. It doesn't remember who you are or what you asked for previously.
Every request is treated as a brand-new interaction. It's like talking to someone with no short-term memory. You have to reintroduce yourself and provide all the context every single time you speak. This is why websites use things like cookies to remember your login information or the items in your shopping cart. Without them, the server would have no idea who you are from one click to the next.
This one-way, stateless communication model built the web we know today. But what happens when you need information instantly, without having to ask for it every second? That's where this simple model starts to show its limits.
