Java Reference
In-Depth Information
Call Socket (W.X.Y.Z, Q)
Blocks
Returns instance
Fill in
local and
remote
address
Closed
Connecting
Established
Handshake
completes
Create
structure
Local port
Local port
P
Local port
P
Local IP
Local IP
A.B.C.D
Local IP
A.B.C.D
Send
connection
request to
server
Remote port
Remote port
Q
Remote port
Q
Remote IP
Remote IP
W.X.Y.Z
Remote IP
W.X.Y.Z
Figure 5.6: Client-side connection establishment.
Let us therefore consider in more detail how the underlying structure gets to and from the
connected, or “Established,” state; as you'll see later (see Section 5.4.2), these details affect the
definition of reliability and the ability to create a Socket or ServerSocket bound to a particular
port.
5.4.1 Connecting
The relationship between an invocation of the Socket constructor and the protocol events
associated with connection establishment at the client are illustrated in Figure 5.6. In this and
the remaining figures of this section, the large arrows depict external events that cause the
underlying socket structures to change state. Events that occur in the application program—
that is, method calls and returns—are shown in the upper part of the figure; events such as
message arrivals are shown in the lower part of the figure. Time proceeds left to right in these
figures. The client's Internet address is depicted as A.B.C.D, while the server's is W.X.Y.Z; the
server's port number is Q.
When the client calls the Socket constructor with the server's Internet address, W.X.Y.Z,
and port, Q, the underlying implementation creates a socket instance; it is initially in the Closed
state. If the client did not specify the local address/port in the constructor call, a local port
number (P), not already in use by another TCP socket, is chosen by the implementation. The
local Internet address is also assigned; if not explicitly specified, the address of the network
interface through which packets will be sent to the server is used. The implementation copies
the local and remote addresses and ports into the underlying socket structure, and initiates
the TCP connection establishment handshake.
The TCP opening handshake is known as a 3-way handshake because it typically involves
three messages: a connection request from client to server, an acknowledgment from server
to client, and another acknowledgment from client back to server. The client TCP considers
the connection to be established as soon as it receives the acknowledgment from the server.
Search WWH ::




Custom Search