-
Notifications
You must be signed in to change notification settings - Fork 5
Iterations
This project involves writing a handful of small, independent servers. You can build them in any order, but we recommend building them in the order presented below.
To connect to a server, use the telnet
command that comes with your computer.
Remember, the absolute, tip-top, #1 priority is asking for and receiving feedback on your code. It's better to "fall short" of an iteration and ask for feedback on an incomplete version than it is to get stuck. It's better to ask for feedback on a hacked-together-but-working version than worry about whether it's "polished enough."
Indeed, even if you know your code is unpolished or incomplete, you may as well ask for feedback so that we can be working on that feedback in parallel while you're polishing or completing your code. The worst that could possibly happen is that we give you feedback you are already aware of.
We've built time_server.rb
for you to show you what a basic network server
looks like and to walk you through the process of connecting to one. To get
started, run this command in your terminal:
ruby time_server.rb
You should see the text "Waiting for connections on port 2000...", like so:
To connect to this time server, open a new terminal window and run
telnet 127.0.0.1 2000
127.0.0.1
is a special IP address that always means "my own computer" and
2000
is the port on which our time server is running. Telnet should exit
almost immediately, but not before receiving the current time from the server,
like so:
An "echo server" reads a single line of input from any client that connects, echoes that same line back to the client, closes the connection, and then starts waiting again for the next client to connect.
You can run
ruby echo_server.rb
but it won't do anything yet. Open up echo_server.rb
and take a stab at
implementing the "echo" functionality.
To check whether your server is doing what you expect, connect to it using
the telnet
command and type a line of text. You should see something like this
once its working correctly:
Feel free to change its behavior — the point is to understand what's going on and get feedback on your implementation!
Let's hook up the "hot or cold" kata from Week 1 to a server. If you don't remember, the "hot or cold" kata is a command-line guessing game that tells us whether our guess is too high, too low, or just right.
See hot_or_cold_server.rb
for more details.
"MOTD" stands for "message of the day." Starting from motd_server.rb
, write a
server that sends every client the contents of motd.txt
.
Write a server of your own! It can do anything you want, honestly. Some areas of investigation might be:
- How do you write a server that can handle multiple clients simultaneously?
- How do you write a server that allows clients to interact with each other, e.g., a chat server?
- What issues would crop up if you started to allow clients to request
arbitrary files from the server rather than a fixed file like
motd.txt
?