Learning Sockets in Python — And It Finally Makes Sense!
Visual inspired by: "anime coder" – via Pinterest Original by: @jay (if known)

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

  • Like a phone call
  • Reliable, in-order, and connection-based
  • Used in web browsing, emails, and file transfers

UDP – Datagram Socket

  • Like sending a postcard
  • No guarantee it’ll be delivered, but it's super fast
  • Used in gaming, streaming, DNS, etc.


TCP Socket Lifecycle (Simplified)

Server Side:

  1. Create socket
  2. Bind to IP + Port
  3. Listen for connections
  4. Accept client requests

Client Side:

  1. Create socket
  2. Connect to the server

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.

To view or add a comment, sign in

More articles by Manoj M

Others also viewed

Explore content categories