Interface SocketOptions
- All Known Implementing Classes:
DatagramSocketImpl
,SocketImpl
public interface SocketOptions
Interface of methods to get/set socket options. This interface is
implemented by
SocketImpl
and DatagramSocketImpl
.
Subclasses of these two classes should override the getOption(int)
and
setOption(int, Object)
methods of this interface in order to support their own options.
The methods and constants defined in this interface are
for implementation only. If you're not subclassing SocketImpl
or
DatagramSocketImpl
, then you won't use these directly. There are
type-safe methods to get/set each of these options in Socket
, ServerSocket
,
DatagramSocket
and MulticastSocket
.
- Since:
- 1.1
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
SeeStandardSocketOptions.IP_MULTICAST_IF
for description of this socket option.static final int
This option is used to both set and fetch the outgoing interface on which the multicast packets are sent.static final int
SeeStandardSocketOptions.IP_MULTICAST_LOOP
for description of this socket option.static final int
SeeStandardSocketOptions.IP_TOS
for description of this socket option.static final int
Fetch the local address binding of a socket.static final int
SeeStandardSocketOptions.SO_BROADCAST
for description of this socket option.static final int
SeeStandardSocketOptions.SO_KEEPALIVE
for description of this socket option.static final int
SeeStandardSocketOptions.SO_LINGER
for description of this socket option.static final int
When this option is set, any TCP urgent data received on the socket will be received through the socket input stream.static final int
SeeStandardSocketOptions.SO_RCVBUF
for description of this socket option.static final int
SeeStandardSocketOptions.SO_REUSEADDR
for description of this socket option.static final int
SeeStandardSocketOptions.SO_REUSEPORT
for description of this socket option.static final int
SeeStandardSocketOptions.SO_SNDBUF
for description of this socket option.static final int
This option is used to both set and fetch a timeout value on blockingSocket
operations: ServerSocket.accept() Socket InputStream.read() DatagramSocket.receive()static final int
SeeStandardSocketOptions.TCP_NODELAY
for description of this socket option. -
Method Summary
-
Field Details
-
TCP_NODELAY
SeeStandardSocketOptions.TCP_NODELAY
for description of this socket option.- See Also:
-
SO_BINDADDR
Fetch the local address binding of a socket. This option cannot be set and can only be fetched. The default local address of a socket isINADDR_ANY
, meaning any local address on a multi-homed host. A multi-homed host can use this option to accept connections to only one of its addresses (in the case of aServerSocket
orDatagramSocket
), or to specify its return address to the peer (for aSocket
orDatagramSocket
). The type of this option's value is anInetAddress
.- See Also:
-
SO_REUSEADDR
SeeStandardSocketOptions.SO_REUSEADDR
for description of this socket option.- See Also:
-
SO_REUSEPORT
SeeStandardSocketOptions.SO_REUSEPORT
for description of this socket option.- Since:
- 9
- See Also:
-
SO_BROADCAST
SeeStandardSocketOptions.SO_BROADCAST
for description of this socket option.- Since:
- 1.4
- See Also:
-
IP_MULTICAST_IF
SeeStandardSocketOptions.IP_MULTICAST_IF
for description of this socket option.- See Also:
-
IP_MULTICAST_IF2
This option is used to both set and fetch the outgoing interface on which the multicast packets are sent. Useful on hosts with multiple network interfaces, where applications want to use other than the system default. This option supports setting outgoing interfaces with either IPv4 and IPv6 addresses.- Since:
- 1.4
- See Also:
-
IP_MULTICAST_LOOP
SeeStandardSocketOptions.IP_MULTICAST_LOOP
for description of this socket option.- Since:
- 1.4
- See Also:
-
IP_TOS
SeeStandardSocketOptions.IP_TOS
for description of this socket option.- Since:
- 1.4
- See Also:
-
SO_LINGER
SeeStandardSocketOptions.SO_LINGER
for description of this socket option.- See Also:
-
SO_TIMEOUT
This option is used to both set and fetch a timeout value on blockingSocket
operations:This option must be set prior to entering a blocking operation to take effect. If the timeout expires and the operation would continue to block, then
InterruptedIOException
is raised. TheSocket
is not closed in such cases.- See Also:
-
SO_SNDBUF
SeeStandardSocketOptions.SO_SNDBUF
for description of this socket option.- See Also:
-
SO_RCVBUF
SeeStandardSocketOptions.SO_RCVBUF
for description of this socket option.- See Also:
-
SO_KEEPALIVE
SeeStandardSocketOptions.SO_KEEPALIVE
for description of this socket option.- See Also:
-
SO_OOBINLINE
When this option is set, any TCP urgent data received on the socket will be received through the socket input stream. When the option is disabled (which is the default) urgent data is silently discarded.- See Also:
-
-
Method Details
-
setOption
Enable/disable the option specified byoptID
. If the option is to be enabled, and it takes an option-specific "value", this is passed invalue
. The actual type ofvalue
is option-specific, and it is an error to pass something that isn't of the expected type:SocketImpl s; ... s.setOption(SO_LINGER, Integer.valueOf(10)); // OK - set SO_LINGER w/ timeout of 10 sec. s.setOption(SO_LINGER, Double.valueOf(10)); // ERROR - expects java.lang.Integer
Boolean
:s.setOption(TCP_NODELAY, Boolean.TRUE); // OK - enables TCP_NODELAY, a binary option
Boolean.FALSE
:s.setOption(TCP_NODELAY, Boolean.FALSE); // OK - disables TCP_NODELAY s.setOption(SO_LINGER, Boolean.FALSE); // OK - disables SO_LINGER
Boolean.FALSE
implicitly enables it.- Parameters:
optID
- identifies the optionvalue
- the parameter of the socket option- Throws:
SocketException
- if the option is unrecognized, the socket is closed, or some low-level error occurred- See Also:
-
getOption
Fetch the value of an option. Binary options will returnBoolean.TRUE
if enabled,Boolean.FALSE
if disabled, e.g.:SocketImpl s; ... Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY)); if (noDelay.booleanValue()) { // true if TCP_NODELAY is enabled... ... }
For options that take a particular type as a parameter, this method will return the parameter's value, else it will return
Boolean.FALSE
:Object o = s.getOption(SO_LINGER); if (o instanceof Integer) { System.out.print("Linger time is " + ((Integer)o).intValue()); } else { // the true type of o is java.lang.Boolean.FALSE; }
- Parameters:
optID
- anint
identifying the option to fetch- Returns:
- the value of the option
- Throws:
SocketException
- if the socket is closed or ifoptID
is unknown along the protocol stack- See Also:
-