Java Reference
In-Depth Information
Socket
,
DatagramSocket
,
MulticastSocket
,
or
ServerSocket
instance
SendQ
To network
RecvQ
Closed
Local port
Underlying socket structure
Local IP
Remote port
Remote IP
Figure 5.1:
Data structures associated with a socket.
about how and when these values are determined shortly (Section 5.5 contains a concise
summary).
A FIFO queue of received data waiting to be delivered and a queue for data waiting to be
transmitted.
For a TCP socket, additional protocol state information relevant to the opening and
closing TCP handshakes. In Figure 5.1, the state is “Closed”; all sockets start out in the
Closed state.
Knowing that these data structures exist and how they are affected by the underlying
protocols is useful because they control various aspects of the behavior of the various
Socket
objects. For example, because TCP provides a
reliable
byte-stream service, a copy of any data
written to a
Socket
's
OutputStream
must be kept until it has been successfully received at the
other end of the connection. Writing data to the output stream does
not
imply that the data has
actually been sent—only that it has been copied into the local buffer. Even
flush()
ing a
Socket
's
OutputStream
doesn't guarantee that anything goes over the wire immediately. Moreover, the
nature of the byte-stream service means that message boundaries are
not
preserved in the
input stream. As we saw in Section 3.3, this complicates the process of receiving and parsing
for some protocols. On the other hand, with a
DatagramSocket
, packets are
not
buffered for
retransmission, and by the time a call to the
send()
method returns, the data has been given to
Search WWH ::
Custom Search