Skip to content

Networking in Python

What is networking?

Networking is how computers exchange data.

Key concepts:

  • IP address: identifies a machine
  • Port: identifies a program/service on that machine
  • Protocol: rules for communication

Common protocols:

  • TCP: reliable (web, SSH)
  • UDP: fast, not guaranteed (streaming, DNS)
  • HTTP/HTTPS: web protocol (built on TCP)

What youโ€™ll learn here

  • Make HTTP requests (APIs) using requestsrequests and urlliburllib
  • Work with JSON data
  • Build a basic HTTP server
  • Use sockets for low-level TCP communication
  • Timeouts, retries, and error handling

Safety note

Always be careful when handling:

  • user input from the internet
  • authentication tokens
  • opening ports on public machines

๐Ÿงช Try It Yourself

Exercise 1 โ€“ HTTP GET with urllib

Exercise 2 โ€“ Socket Connection

Exercise 3 โ€“ Resolve a Hostname

If this helped you, consider buying me a coffee โ˜•

Buy me a coffee

Was this page helpful?

Let us know how we did