Clients and Servers
Lesson 2 of 47 in Coddy's Networking with the Terminal course.
In every exchange one side starts the conversation and the other waits for it. The side that asks is the client. The side that waits and answers is the server.
These are roles, not machines. The same computer is a server when it answers a web request and a client a second later when it queries a database. Your laptop is usually a client, but the moment you start a local development server it is a server too.
A server does something specific and slightly odd: it starts up and then waits, doing nothing, sometimes for weeks. It is listening. When a request finally arrives it answers and goes back to waiting.
The client has to know where to send its request, and the server has to be listening in the right place for it to arrive. That is the whole handshake, and when something is broken it is almost always one of those two halves.
Challenge
EasyPut a server into the listening state, then check it is really waiting.
- Start a server on port 9102 in the background
- Give it a second to come up
- Knock on the port with
nc -zand printlisteningif something answers, ornothingif not
Expected output:
listening
command && echo a || echo bprintsawhen the command succeeds andbwhen it fails.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
Practice on your own: Terminal playground