Foundations of Python Network Programming

(WallPaper) #1
57

Chapter 4

Socket Names and DNS


Having spent the previous two chapters learning the basics of UDP and TCP, the two major data transports available
on IP networks, it is time for me to step back and talk about two larger issues that need to be tackled, regardless of
which data transport you are using. In this chapter, I will discuss the topic of network addresses, and I will describe
the distributed service that allows names to be resolved to raw IP addresses.


Hostnames and Sockets


We rarely type raw IP addresses into our browser or e-mail client. Instead, we type domain names. Some domain
names identify entire organizations, like python.org and bbc.co.uk, while others name specific hosts or services, like
http://www.google.com or asaph.rhodesmill.org. Some sites let you abbreviate a hostname by simply typing asaph, and
they will automatically fill in the rest of the name for you by assuming you mean the asaph machine there at the same
site. However, it is always correct, regardless of any local customization, to specify a fully qualified domain name that
includes all of the pieces up to and including the top-level domain.
The idea of a top-level domain (TLD) used to be simple: it was either .com, .net, .org, .gov, .mil, or a two-letter
internationally recognized country code like .uk. But today many other, more frivolous, top-level domains like .beer
are being added, which will make it a bit more difficult to distinguish fully qualified from partially qualified domain
names at a glance (unless you try to keep the whole list of top-level names memorized!).
Typically, each TLD has its own set of servers and is run by an organization that is in charge of granting
ownership to domains beneath the TLD. When you sign up for a domain, they add an entry for it to their servers.
Then, when a client running anywhere in the world wants to resolve a name that is within your domain, the top-level
servers can refer the client to your own domain servers so that your organization can return the addresses it wants for
the various hostnames you create. The collection of servers worldwide that answer name requests using this system of
top-level names and referrals together provide the Domain Name Service (DNS).
The previous two chapters have already introduced you to the fact that sockets cannot be named with a single
primitive Python value like a number or string. Instead, both TCP and UDP use integer port numbers to share a single
machine’s IP address among the many different applications that might be running there, and so the address and port
number have to be combined in order to produce a socket name, like this:


('18.9.22.69', 80)


While you might have been able to pick up some scattered facts about socket names from the previous few
chapters—like the fact that the first item can be either a hostname or a dotted IP address—it is time to approach the
whole subject in more depth.

Free download pdf