java.net.SocketOptions |
![]() |
Defines an interface for socket implementations to get and set socket
options. It is implemented by the classes SocketImpl
and DatagramSocketImpl
.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | IP_MULTICAST_IF | This option specifies the interface which is used to send multicast packets. | |||||||||
int | IP_MULTICAST_IF2 | This option can be used to set one specific interface on a multihomed host on which incoming connections are accepted. | |||||||||
int | IP_MULTICAST_LOOP | This option specifies whether the local loopback of multicast packets is enabled or disabled. | |||||||||
int | IP_TOS | This option specifies the value for the Type-of-Service (TOS) field of the IP header. | |||||||||
int | SO_BINDADDR | This option can be used to set one specific interface on a multihomed host on which incoming connections are accepted. | |||||||||
int | SO_BROADCAST | This option can be used to enable broadcasting on datagram sockets. | |||||||||
int | SO_KEEPALIVE | This option specifies whether socket implementations can send keepalive messages if no data has been sent for a longer time. | |||||||||
int | SO_LINGER | This option specifies the behavior of the close() method if there
is still some buffered data to be sent while closing the socket. | |||||||||
int | SO_OOBINLINE | This option specifies whether sending TCP urgent data is supported on this socket or not. | |||||||||
int | SO_RCVBUF | Buffer size of the incoming channel. | |||||||||
int | SO_REUSEADDR | This option specifies whether a reuse of a local address is allowed even if an other socket is not yet removed by the operating system. | |||||||||
int | SO_SNDBUF | Buffer size of the outgoing channel. | |||||||||
int | SO_TIMEOUT | Timeout for blocking accept or read/receive operations (but not write/send operations). | |||||||||
int | TCP_NODELAY | This option specifies whether data is sent immediately on this socket, as a side-effect though, this could lead to a low packet efficiency. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the value for the specified socket option.
| |||||||||||
Sets the value of the specified socket option.
|
This option specifies the interface which is used to send multicast
packets. It's only available on a MulticastSocket
.
This option can be used to set one specific interface on a multihomed host on which incoming connections are accepted. It's only available on server-side sockets. This option supports setting outgoing interfaces with either IPv4 or IPv6 addresses.
This option specifies whether the local loopback of multicast packets is enabled or disabled. This option is enabled by default on multicast sockets.
This option specifies the value for the Type-of-Service (TOS) field of the IP header. This may be ignored by the underlying OS. Values must be between 0 and 255 inclusive. See RFC 1349 for more information.
This option can be used to set one specific interface on a multihomed host on which incoming connections are accepted. It's only available on server-side sockets.
This option can be used to enable broadcasting on datagram sockets.
This option specifies whether socket implementations can send keepalive messages if no data has been sent for a longer time.
This option specifies the behavior of the close()
method if there
is still some buffered data to be sent while closing the socket. If the
value of this option is set to 0
the method closes the TCP socket
forcefully and returns immediately. Is this value greater than 0
the method blocks this time in milliseconds. If all data could be sent
during this timeout the socket is closed normally otherwise forcefully.
Valid values for this option are in the range 0 <_ so_linger="so_linger" _="65535</code">. (Larger timeouts will be treated as 65535s timeouts; roughly 18 hours.)
Constant Value:
128
(0x00000080)
public
static
final
int
SO_OOBINLINE
Since: API Level 1
This option specifies whether sending TCP urgent data is supported on
this socket or not.
Constant Value:
4099
(0x00001003)
public
static
final
int
SO_RCVBUF
Since: API Level 1
Buffer size of the incoming channel.
Constant Value:
4098
(0x00001002)
public
static
final
int
SO_REUSEADDR
Since: API Level 1
This option specifies whether a reuse of a local address is allowed even
if an other socket is not yet removed by the operating system. It's only
available on a
MulticastSocket
.
Constant Value:
4
(0x00000004)
public
static
final
int
SO_SNDBUF
Since: API Level 1
Buffer size of the outgoing channel.
Constant Value:
4097
(0x00001001)
public
static
final
int
SO_TIMEOUT
Since: API Level 1
Timeout for blocking accept or read/receive operations (but not write/send operations).
The argument value is specified in milliseconds, with 0 meaning no timeout and negative
values not allowed.
An
InterruptedIOException
is thrown if this timeout expires.
Constant Value:
4102
(0x00001006)
public
static
final
int
TCP_NODELAY
Since: API Level 1
This option specifies whether data is sent immediately on this socket, as
a side-effect though, this could lead to a low packet efficiency. The
socket implementation uses the Nagle's algorithm to try to reach a higher
packet efficiency if this option is disabled.
Constant Value:
1
(0x00000001)
Public Methods
public
abstract
Object
getOption
(int optID)
Since: API Level 1
Gets the value for the specified socket option.
Parameters
optID
| the option identifier. |
---|
Returns
the option value.
public
abstract
void
setOption
(int optID, Object val)
Since: API Level 1
Sets the value of the specified socket option.
Parameters
optID
| the option identifier. |
---|---|
val
| the value to be set for the option. |