Susan Potter
software: Created / Updated

A WebSockets Story

It was a cold and blustery day, and Susan sat huddled in front of her recent birthday present to herself - a ThinkPad running NixOS - her fingers numb with cold. She had been struggling for hours - well, at least 3 minutes which felt like hours - to establish a connection with the server, and she was starting to lose hope.

But Susan was a determined young lady (ok, she's a stubborn middle-aged woman), and she refused to give up now. She knew that if she could just get this WebSocket connection to work, it would open up a whole world of possibilities for her new web app side project.

So she hunched over her keyboard and began crafting a special HTTP request. "Please, server," she whispered. "Upgrade me to a WebSocket connection."

To her delight, the server answered her prayer!

It sent back an HTTP response, its "Upgrade" header shining like a beacon of hope in the darkening sky.

But the server wasn't done yet. It also included a preternatural, base64-encoded string in its response - the "Sec-WebSocket-Accept" header. Susan had no idea what it meant, but she knew it was important.

Enter DuckDuckGo.

She discovered that this header was the result of a secret handshake between the client and the server. It was a way of proving to each other that they were both truly who they claimed to be.

And so, with the handshake complete, Susan and the server were able to send messages back and forth over their newly-established WebSocket connection. It was a joyous occasion, one that Susan would always remember with fondness and later even toot about.

As the day turned to night, Susan and the server chatted away, discussing all manner of topics including the frustration of developing non-Apple software on macOS especially on installations riddled with corporate spyware.

They laughed, they learned, and they even sang some songs from the 1990s together. It was a magical evening, made all the more special by the power of WebSockets.

In case you are wondering, I am rereading Villette (by Charlotte Bronte). Above I missed incorporating a massive disdain that the protagonist had toward the overly religious natives of the country she moved to (an enormous theme of the book), but it seemed less relevant in this context. :)

If you enjoyed this content, please consider sharing this link with a friend, following my GitHub or LinkedIn accounts, or subscribing to my RSS feed.