Java Reference
In-Depth Information
Incoming
connection
request
from
A.B.C.D/P
Listening
Listening
Listening
Local port
Q
Local port
Q
Local port
Q
Local IP
*
Local IP
*
Local IP
*
Remote port
*
Remote port
*
Remote port
*
Remote IP
*
Remote IP
*
Remote IP
*
Create new structure
and continue handshake
Connecting
Established
Handshake
completes
Local port
Q
Local port
Q
Local IP
W.X.Y.Z
Local IP
W.X.Y.Z
Remote port
P
Remote port
P
Remote IP
A.B.C.D
Remote IP
A.B.C.D
Figure 5.8: Incoming connection request processing.
When the request for a connection arrives from the client, a new socket structure is
created for the connection. The new socket's addresses are filled in based on the arriving packet:
the packet's destination Internet address and port (W.X.Y.Z and Q, respectively) become the
local Internet address and port; the packet's source address and port (A.B.C.D and P) become
the remote Internet address and port. Note that the local port number of the new socket is
always the same as that of the ServerSocket . The new socket's state is set to “Connecting”,
and it is added to a list of not-quite-connected sockets associated with the socket structure of
the ServerSocket . Note that the ServerSocket itself does not change state, nor does any of its
address information change.
In addition to creating a new underlying socket structure, the server-side TCP implemen-
tation sends an acknowledging TCP handshake message back to the client. However, the server
TCP does not consider the handshake complete until the third message of the 3-way handshake
is received from the client. When that message eventually arrives, the new structure's state is
set to “Established”, and it is then (and only then) moved to a list of socket structures asso-
ciated with the ServerSocket structure, which represent established connections ready to be
accept() ed via the ServerSocket . (If the third handshake message fails to arrive, eventually the
“Connecting” structure is deleted.)
Search WWH ::




Custom Search