Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The last chapter discussed sockets from the standpoint of
clients: programs that open a socket to a server
that’s listening for connections. However, client sockets themselves
aren’t enough; clients aren’t much use unless they can talk to a server,
and the Socket class discussed in the
last chapter is not sufficient for writing servers. To create a Socket, you need to know the Internet host to
which you want to connect. When you’re writing a server, you don’t know in
advance who will contact you, and even if you did, you wouldn’t know when
that host wanted to contact you. In other words, servers are like
receptionists who sit by the phone and wait for incoming calls. They don’t
know who will call or when, only that when the phone rings, they have to
pick it up and talk to whoever is there. You can’t program that behavior
with the