Java Reference
In-Depth Information
localAddr
The IP address to which connections to this socket should be
addressed (must be one of the local interface addresses). If the
address is not specified, the socket will accept connections to
any of the host's IP addresses. This may be useful for hosts
with multiple interfaces where the server socket should only
accept connections on one of its interfaces.
Operators
Socket accept ()
Returns a connected Socket instance for the next new incoming connection to the
server socket. If no established connection is waiting, accept() blocks until one is
established or a timeout occurs (see setSoTimeout() ).
void close ()
Closes the underlying TCP socket. After invoking this method, incoming client con-
nection requests for this socket are rejected.
Accessors/Mutators
InetAddress getInetAddress()
int getLocalPort ()
Returns the local address/port of the server socket.
int getSoTimeout ()
void setSoTimeout ( int timeout )
Returns/sets the maximum amount of time (in milliseconds) that an accept() will
block for this socket. If the timer expires before a connection request arrives, an
InterruptedIOException is thrown. A timeout value of 0 indicates no timeout: calls
to accept() will not return until a new connection is available, regardless of how much
time passes (see Section 4.2).
2.2.3 Input and Output Streams
As illustrated by the examples above, the primary paradigm for I/O in Java is the stream
abstraction. A stream is simply an ordered sequence of bytes. Java input streams support
reading bytes, and output streams support writing bytes. In our TCP client and server, each
Socket instance holds an InputStream and an OutputStream instance. When we write to the
output stream of a Socket , the bytes can (eventually) be read from the input stream of the
Socket at the other end of the connection.
OutputStream is the abstract superclass of all output streams in Java. Using an Output−
Stream , we can write bytes to, flush, and close the output stream.
Search WWH ::




Custom Search