Menu
Coddy logo textTech

Sockets in Action

Lesson 19 of 32 in Coddy's The OSI Model course.

An IP address plus a port, bound together inside a program, is a socket. A server listens on a socket; a client connects to it. That is layer 4 made concrete.

You can watch it happen with two tools you already have: python3 -m http.server PORT starts a listening server, and nc -z host port knocks on a port and reports (via its exit status) whether anything answered.

Servers take a moment to come up, so real scripts retry the knock a few times before concluding anything.

challenge icon

Challenge

Medium

Open a socket and prove it is listening:

  1. Start a server on port 9210 in the background
  2. Wait for it to come up
  3. Knock with nc -z and print open if it answers, or closed if not

Expected output:

open

Try it yourself

Terminal

All lessons in The OSI Model

Practice on your own: Terminal playground