Day 512

Chep
2 min readAug 16, 2023

--

web sockets generated from firefly

A technical explanation of web sockets aimed at senior software engineers:

Web sockets provide full-duplex communication channels over a single TCP connection. The web socket protocol (RFC 6455) enables bidirectional data transfer between a client and server, allowing for real-time data exchange.

A web socket connection is initiated with a HTTP handshake between the client and server. This handshake upgrades the connection from HTTP to the web socket protocol. Once established, communication switches from HTTP’s request-response model to a message-based model where either side can send data at any time, much like a raw TCP socket.

Messages sent over a web socket can be text or binary data. Optional extensions to the protocol also support compression, authentication and other features.

Compared to REST APIs or polling, web sockets reduce latency by eliminating the need for the client to constantly poll for updates. Web sockets also use less resources since an open connection is maintained instead of opening and closing new connections.

Common uses of web sockets include online games, real-time web apps like chat, notifications, collaborating on documents, and streaming financial/market data. The web socket API is well supported across modern browsers and languages like JavaScript, Java, Python and C#.

For security, web sockets should use the WSS protocol which connects over TLS to encrypt communication. Authorization, authentication and access token mechanisms can also be implemented in the web socket server to identify and validate clients.

Today I didn’t fully understand what websockets were, but after doing some research I now see they allow full-duplex communication between a client and server, enabling real-time data transfer. The significance of web sockets in applications like instantaneous messaging and live updates became evident, owing to their capacity to maintain an open connection and facilitate swift data dissemination sans polling.

I started learning about websockets today because I was curious what the difference is between a normal API call and a websocket. Going down this computer science rabbit hole has shown me just how amazing our human mind is. It reminds me that our ability to think in abstract ways is what sets us apart from other animals. Our minds can create mental structures that help us understand ideas that aren’t physical. This ability allows us to understand complex things and how they relate to each other.

Think of it like building a puzzle in your mind. Even if the pieces aren’t real, you can still put them together to see the whole picture. This way of thinking helps us come up with new ideas, solve problems, and learn more about the world around us. For example, Twitter is not a real place in meat space, but when I say I saw that on Twitter other humans know exactly what I’m talking about.

8/16/23

Conor Jay Chepenik

--

--

Chep
Chep

Written by Chep

I've decided to write everyday for the rest of my life or until Medium goes out of business.

No responses yet