Java Reference
In-Depth Information
Once you have an InetAddress instance, you can interrogate it by invoking in-
stancemethodssuchas byte[] getAddress() (returntherawIPaddress[innet-
work byte order] of this InetAddress object) and boolean isLoopbackAd-
dress() (determine whether or not this InetAddress instance represents a loop-
back address).
Java 1.4 introduced the abstract java.net.SocketAddress class to represent
asocketaddress“withnoprotocolattachment.”Perhapsthisclass'screatoranticipated
that Java would eventually support low-level communication protocols other than the
widely popular Internet Protocol.
SocketAddress is subclassed by the concrete
java.net.InetSocketAddress class,whichrepresentsasocketaddressasanIP
addressandaportnumber.Itcanalsorepresentahostnameandaportnumber,andwill
make an attempt to resolve the hostname.
InetSocketAddress instances are created by invoking constructors such as
InetSocketAddress(InetAddress addr, int port) . After an instance
hasbeencreated,youcancallmethodssuchas InetAddress getAddress() and
int getPort() to return socket address components.
Socket Options
Aswellassharingtheconceptofsocketaddresses,thevarious Socket -suffixedclasses
sharetheconceptofsocketoptions.A socket option isaparameterforconfiguringsock-
etbehavior.ThefollowingClanguageconstantsidentifysocketoptionsthatthe Sock-
et -suffixed classes support via various methods:
TCP_NODELAY : Disable Nagle's algorithm
( http://en.wikipedia.org/wiki/Nagle's_algorithm ) . This
option is valid for Socket .
SO_LINGER : Specify a linger-on-close timeout. This option is valid for
Socket .
SO_TIMEOUT :Specifyatimeoutonblockingsocketoperations.(Don'tblock
forever!) This option is valid for Socket , ServerSocket , and Data-
gramSocket .
SO_BINDADDR : Fetch the socket's local address binding. This option is valid
for Socket , ServerSocket , and DatagramSocket .
SO_REUSEADDR : Enable a socket's reuse address. This option is valid for
Socket , ServerSocket , and DatagramSocket .
Search WWH ::




Custom Search