4/20+1, 2021

Written politely 2021-04-21.

Server Sockets Spraying ClientS

WebSockets are the social web connection that power apps like messengers and polling systems, on the web. They allow users to send packets back and forth without a new handshake each time, unlike an XHR. When sockets are used, there isn’t a need to keep polling the server which is inprecise and can be a memory hog because of all the constant checks to see if an update is available. With a WebSocket, you open a connection and leave it open until the process is ended on either the server, which would terminate the process for all clients, or on the client, such as when closing a tab with a messenger service open. The WebSocket is still open on the server and ready to recieve packets from an approved client with only a single new handshake.

Socket.io

So, you can use a variety of tools in JavaScript to make using sockets a breeze. I decided to use Socket.io which is a popular library. I went through their tutorial and have it here in my Gitlab repo. I found their documents clear and the tutorial was straightforward, simple, and effective at seeing the wide array of applications that this could be used in. If the data changes on the server, the event triggers an event and broadcasts it to all of the connected clients. It creates the potential to have a group web connection only limited by the power of the server and the latency in their connection.

Always Be Coding

Go forth and build something with WebSockets or share an appliction idea that would be a cash cow using WebSockets and let’s build something together.


Lucas McDaniel

Husband, father, teacher, musician, avid gamer, nature enthusiast, and passionate about the human condition.