domain name server—a program on the Net that serves the same purpose as your
local telephone directory assistance service. As a special case, the machine name
localhost, and its equivalent IP address 127.0.0.1, always mean the same local
machine; this allows us to refer to servers running locally on the same computer
as its clients.
Port numbers
A port number is an agreed-upon numeric identifier for a given conversation. Be-
cause computers on the Net support a variety of services, port numbers are used
to name a particular conversation on a given machine. For two machines to talk
over the Net, both must associate sockets with the same machine name and port
number when initiating network connections. As we’ll see, Internet protocols such
as email and the Web have standard reserved port numbers for their connections,
so clients can request a service regardless of the machine providing it. Port number
80 , for example, usually provides web pages on any web server machine.
The combination of a machine name and a port number uniquely identifies every dialog
on the Net. For instance, an ISP’s computer may provide many kinds of services for
customers—web pages, Telnet, FTP transfers, email, and so on. Each service on the
machine is assigned a unique port number to which requests may be sent. To get web
pages from a web server, programs need to specify both the web server’s Internet Pro-
tocol (IP) or domain name and the port number on which the server listens for web
page requests.
If this sounds a bit strange, it may help to think of it in old-fashioned terms. To have a
telephone conversation with someone within a company, for example, you usually need
to dial both the company’s phone number and the extension of the person you want
to reach. If you don’t know the company’s number, you can probably find it by looking
up the company’s name in a phone book. It’s almost the same on the Net—machine
names identify a collection of services (like a company), port numbers identify an in-
dividual service within a particular machine (like an extension), and domain names are
mapped to IP numbers by domain name servers (like a phone book).
When programs use sockets to communicate in specialized ways with another machine
(or with other processes on the same machine), they need to avoid using a port number
reserved by a standard protocol—numbers in the range of 0 to 1023—but we first need
to discuss protocols to understand why.
The Protocol Layer
Although sockets form the backbone of the Internet, much of the activity that happens
on the Net is programmed with protocols,† which are higher-level message models that
† Some books also use the term protocol to refer to lower-level transport schemes such as TCP. In this book,
we use protocol to refer to higher-level structures built on top of sockets; see a networking text if you are
curious about what happens at lower levels.
782 | Chapter 12: Network Scripting