You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jesse Farmer edited this page Jun 9, 2014
·
2 revisions
A Sequence of Simple Servers
In this project, we're going to try to understand more about how computers talk
to each other over a network. To do that, we're going to actually build a
handful of very simple internet servers and connect to them using tools
that come with our computers.
The idea of "writing a network server in Ruby" probably seems crazy, but our
first server will be about 20 lines long (excluding comments). This is a
real-deal server. You could put it on an Amazon EC2 instance, run it, and any computer
in the world would be able to connect to it, if that's what you wanted.
Server software is no more complicated than any other kind of software. In fact,
we'll be re-designing some of our command-line software to run remotely and
you'll see how little "re-design" is actually needed.
The Basics of Computer Networking
The most common type of computer networking involves one computer acting as
a "client" and another acting as a "server." The server is running some
software that the client wants to make use of. It connects to the server, uses
the software (as the server permits), and then either ends the connection itself
or waits for the server to end the connection.
One of the easiet-to-understand examples is a file server. There's a computer
somewhere with a bunch of files on it. Other computers connect to it in order
to access those files. Perhaps the file server allows users to copy files to
their own computers but not delete them from the server itself.
Servers listen for incoming connections while clients make outbound connections.
Hosts and Ports
To connect to a service running on another computer, you need two pieces of
information: a host name (or IP address) and a port number.
The host name (or IP address) identifies the computer on the internet, much
like a phone number does on a telephone network. The port number is an
extra bit of information which tells the remote computer which service
we want to use, much like a telephone extension.
We need this extra piece of information because a single computer can be running
multiple pieces of server software, e.g., a web server, a file server, a mail
server, and so on. Each server runs on a single port, so that the remote
computer knows which piece of server software is responsible for handling the
client.
Host names look like "cnn.com", "facebook.com", and so on. IP addresses look
like "74.125.239.38", "173.252.110.27", and so on. Port numbers are just
plain numbers. If you've ever seen a URL that looks like
www.google.com:1234
That 1234 is a port number.
Server Software vs. Server Hardware
Software engineers use the word "server" to mean two different things:
The computer on which server software is running
The server software itself
To a computer (the client) trying to connect to a remote service, the
distinction doesn't much matter, which is why engineers use the word to mean
both things in casual conversation.
Likewise, when we say "client" we sometimes mean the software making the
connection (e.g., your web browser) or the computer on which that software is
running.
Since we'll be running our server software on our own computers, we'll
almost always mean "server software" when we say "server." We'll let you know
when the distinction is important.