Java Reference
In-Depth Information
chapter 5
Under the Hood
S ome of the subtleties of network programming are dicult to grasp without some
understanding of the data structures associated with the socket implementation and certain
details of how the underlying protocols work. This is especially true of TCP sockets (i.e.,
instances of Socket ). This chapter describes some of what goes on under the hood when you
create and use an instance of Socket or ServerSocket . (The initial discussion and Section 5.5
apply as well to DatagramSocket and MulticastSocket . However, most of this chapter focuses
on TCP sockets, that is, Socket and ServerSocket .) Please note that this description covers only
the normal sequence of events and glosses over many details. Nevertheless, we believe that
even this basic level of understanding is helpful. Readers who want the full story are referred
to the TCP specification [13] or to one of the more comprehensive treatises on the subject [3,
22].
Figure 5.1 is a simplified view of some of the information associated with a Socket
instance. The classes are supported by an underlying implementation that is provided by
the JVM and/or the platform on which it is running (i.e., the “socket layer” of the host's OS).
Operations on the Java objects are translated into manipulations of this underlying abstraction.
In this chapter, “ Socket ” refers generically to one of the classes in Figure 5.1, while “socket”
refers to the underlying abstraction, whether it is provided by an underlying OS or the JVM
implementation itself (e.g., in an embedded system). It is important to note that other (possibly
non-Java) programs running on the same host may be using the network via the underlying
socket abstraction, and thus competing with Java Socket instances for resources such as ports.
By “socket structure” here we mean the collection of data structures in the underlying
implementation (of both the JVM and TCP/IP, but primarily the latter) that contain the informa-
tion associated with a particular Socket instance. For example, the socket structure contains,
among other information
The local and remote Internet addresses and port numbers associated with the socket.
The local Internet address (labeled “Local IP” in the figure) is one of those assigned to
the local host; the local port is set at Socket creation time. The remote address and port
identify the remote socket, if any, to which the local socket is connected. We will say more
93
Search WWH ::




Custom Search