Kamran Mushtaq
Back to Networking
Networking

Socket

Added: June 15, 2026Nurtured: June 20, 2026

Definition

A Socket is a communication endpoint created using an IP Address and a Port Number which allows two applications to exchange data.

What Problem It Solves

Sockets solve the complexity of low-level networking by abstracting the IP and Port details into a simple read/write file descriptor interface. It establishes a live, bidirectional communication line that developers can easily write to and read from in code.

What Happens If Not Used

Without sockets, developers would have to manually implement packet segmentation, TCP handshakes, checksum verifications, and state tracking for every network request they make.

Easy Wording

A socket is an open, live communication line between two programs.

Layman Example

Suppose:

Hotel Address = IP Address
Room Number = Port
Telephone Call = Socket

When call starts:

Hotel
↓
Room 443
↓
Phone Connected
↓
Conversation Begins

That's a socket.

Technical Example

You open https://google.com:

  1. DNS lookup: google.com -> 142.250.xx.xx
  2. Endpoint knowledge: Browser knows IP: 142.250.xx.xx, Port: 443
  3. Socket creation: Browser creates a socket to 142.250.xx.xx:443
  4. TCP Handshake:
    • Browser: "Can I connect?"
    • Google: "Yes"
    • Browser: "Let's communicate"
  5. Data Transfer:
    • Browser sends GET / through socket
    • Google responds with HTML page through socket
  6. Connection Teardown: Browser closes the socket, ending the communication.