Interface SocketOptions
- All Known Implementing Classes:
DatagramSocketImpl,SocketImpl
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
FieldsModifier and TypeFieldDescriptionstatic final intSeeStandardSocketOptions.IP_MULTICAST_IFfor description of this socket option.static final intThis option is used to both set and fetch the outgoing interface on which the multicast packets are sent.static final intSeeStandardSocketOptions.IP_MULTICAST_LOOPfor description of this socket option.static final intSeeStandardSocketOptions.IP_TOSfor description of this socket option.static final intFetch the local address binding of a socket.static final intSeeStandardSocketOptions.SO_BROADCASTfor description of this socket option.static final intSeeStandardSocketOptions.SO_KEEPALIVEfor description of this socket option.static final intSeeStandardSocketOptions.SO_LINGERfor description of this socket option.static final intWhen this option is set, any TCP urgent data received on the socket will be received through the socket input stream.static final intSeeStandardSocketOptions.SO_RCVBUFfor description of this socket option.static final intSeeStandardSocketOptions.SO_REUSEADDRfor description of this socket option.static final intSeeStandardSocketOptions.SO_REUSEPORTfor description of this socket option.static final intSeeStandardSocketOptions.SO_SNDBUFfor description of this socket option.static final intThis option is used to both set and fetch a timeout value on blockingSocketoperations: ServerSocket.accept() Socket InputStream.read() DatagramSocket.receive()static final intSeeStandardSocketOptions.TCP_NODELAYfor description of this socket option. -
Method Summary
-
Field Details
-
TCP_NODELAY
SeeStandardSocketOptions.TCP_NODELAYfor 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 aServerSocketorDatagramSocket), or to specify its return address to the peer (for aSocketorDatagramSocket). The type of this option's value is anInetAddress.- See Also:
-
SO_REUSEADDR
SeeStandardSocketOptions.SO_REUSEADDRfor description of this socket option.- See Also:
-
SO_REUSEPORT
SeeStandardSocketOptions.SO_REUSEPORTfor description of this socket option.- Since:
- 9
- See Also:
-
SO_BROADCAST
SeeStandardSocketOptions.SO_BROADCASTfor description of this socket option.- Since:
- 1.4
- See Also:
-
IP_MULTICAST_IF
SeeStandardSocketOptions.IP_MULTICAST_IFfor 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_LOOPfor description of this socket option.- Since:
- 1.4
- See Also:
-
IP_TOS
SeeStandardSocketOptions.IP_TOSfor description of this socket option.- Since:
- 1.4
- See Also:
-
SO_LINGER
SeeStandardSocketOptions.SO_LINGERfor description of this socket option.Set the value to
Boolean.FALSEor an integer less than0withsetOption(int, Object)to disable this option. An integer greater than or equal to0will enable the option and will represent the linger interval.If this option is enabled then
getOption(int)will return an integer value representing the linger interval, else the return value will beBoolean.FALSE.- See Also:
-
SO_TIMEOUT
This option is used to both set and fetch a timeout value on blockingSocketoperations: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
InterruptedIOExceptionis raised. TheSocketis not closed in such cases.- See Also:
-
SO_SNDBUF
SeeStandardSocketOptions.SO_SNDBUFfor description of this socket option.- See Also:
-
SO_RCVBUF
SeeStandardSocketOptions.SO_RCVBUFfor description of this socket option.- See Also:
-
SO_KEEPALIVE
SeeStandardSocketOptions.SO_KEEPALIVEfor 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 ofvalueis option-specific, and it is an error to pass something that isn't of the expected type:If the requested option is binary, it can be set using this method by aSocketImpl 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.IntegerBoolean:Any option can be disabled using this method with as.setOption(TCP_NODELAY, Boolean.TRUE); // OK - enables TCP_NODELAY, a binary optionBoolean.FALSE:For an option that has a notion of on and off, and requires a non-boolean parameter, setting its value to anything other thans.setOption(TCP_NODELAY, Boolean.FALSE); // OK - disables TCP_NODELAY s.setOption(SO_LINGER, Boolean.FALSE); // OK - disables SO_LINGERBoolean.FALSEimplicitly 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.TRUEif enabled,Boolean.FALSEif 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- anintidentifying the option to fetch- Returns:
- the value of the option
- Throws:
SocketException- if the socket is closed or ifoptIDis unknown along the protocol stack- See Also:
-