Learning Sockets in Python — And It Finally Makes Sense!
What the heck is a Socket?
Lately, I’ve been diving into the basics of networking — and I finally wrapped my head around sockets. Thought I’d write this down in the way I wish someone had explained it to me.
So here’s the brain dump
A socket is the endpoint for communication between two devices. If the internet were a massive phone line, sockets are like the phones at each end.
Think of it like this: I dial your number (IP + Port), we both pick up (connect), and then we can send messages back and forth.
Basic Networking 101
IP Address → Where your device lives on the network Port Number → The exact service or app inside your device
Together, IP + Port is like: #302, Sunshine Apartments — the network knows exactly where to deliver the message.
Types of Sockets
TCP – Stream Socket
UDP – Datagram Socket
Recommended by LinkedIn
TCP Socket Lifecycle (Simplified)
Server Side:
Client Side:
After that, they can both send and receive messages!
TCP vs UDP – Quick Comparison
Feature TCP/UDP Connection Yes (Reliable)No (Connectionless) Ordering Guaranteed Not guaranteed Use Cases Web, Email, FTP, Games, Video Streams
Why I’m Posting This
I recently built a small Python project using the socket module, a basic TCP server, and client.
It’s simple, but something clicked. I finally saw how devices actually talk to each other over the network. And now I want to keep exploring this rabbit hole 🐇
If you're just getting into network programming or curious how your favorite apps communicate behind the scenes, I highly recommend playing with raw sockets at least once!
Wanna Try It Yourself?
I’ve pushed the code to GitHub here: https://github.com/M-an-o-j/basic_socket
Feel free to fork it, play with it, or even break it. That’s how I’m learning, too.