Enable/disable the option specified by
optID. If the option
is to be enabled, and it takes an option-specific "value", this is
passed in
value. The actual type of value is option-specific,
and it is an error to pass something that isn't of the expected type:
SocketImpl s;
...
s.setOption(SO_LINGER, new Integer(10));
// OK - set SO_LINGER w/ timeout of 10 sec.
s.setOption(SO_LINGER, new Double(10));
// ERROR - expects java.lang.Integer
If the requested option is binary, it can be set using this method by
a java.lang.Boolean:
s.setOption(TCP_NODELAY, new Boolean(true));
// OK - enables TCP_NODELAY, a binary option
Any option can be disabled using this method with a Boolean(false):
s.setOption(TCP_NODELAY, new Boolean(false));
// OK - disables TCP_NODELAY
s.setOption(SO_LINGER, new Boolean(false));
// OK - disables SO_LINGER
For an option that has a notion of on and off, and requires
a non-boolean parameter, setting its value to anything other than
Boolean(false) implicitly enables it.
Throws SocketException if the option is unrecognized,
the socket is closed, or some low-level error occurred
Parameters:
-
optID - identifies the option
-
value - 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:
SocketOptions.getOption(int)
,