java.net.SocketOptions |
Known Indirect Subclasses |
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 | The interface 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 field of the IPv4 header, or the traffic class field of the IPv6 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 | Number of seconds to wait when closing a socket if there is still some buffered data to be sent. | |||||||||
int | SO_OOBINLINE | This boolean option specifies whether sending TCP urgent data is supported on this socket or not. | |||||||||
int | SO_RCVBUF | The size in bytes of a socket's receive buffer. | |||||||||
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 | The size in bytes of a socket's send buffer. | |||||||||
int | SO_TIMEOUT | Timeout in milliseconds for blocking accept or read/receive operations (but not write/send operations). | |||||||||
int | TCP_NODELAY | Whether data is sent immediately on this socket. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the value for the specified socket option.
| |||||||||||
Sets the value of the specified socket option.
|
The interface used to send multicast packets.
This option is 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 field of the IPv4 header, or the traffic class field of the IPv6 header. These correspond to the IP_TOS and IPV6_TCLASS socket options. These may be ignored by the underlying OS. Values must be between 0 and 255 inclusive.
See RFC 1349 for more about IPv4 and RFC 2460 for more about IPv6.
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.
Number of seconds to wait when closing a socket if there is still some buffered data to be sent.
If this option is set to 0, the TCP socket is closed forcefully and the
call to close
returns immediately.
If this option is set to a value greater than 0, the value is interpreted as the number of seconds to wait. If all data could be sent during this time, the socket is closed normally. Otherwise the connection will be closed forcefully.
Valid values for this option are in the range 0 to 65535 inclusive. (Larger timeouts will be treated as 65535s timeouts; roughly 18 hours.)
This boolean option specifies whether sending TCP urgent data is supported on this socket or not.
The size in bytes of a socket's receive buffer. This must be an integer greater than 0. This is a hint to the kernel; the kernel may use a larger buffer.
For datagram sockets, packets larger than this value will be discarded.
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
.
The size in bytes of a socket's send buffer. This must be an integer greater than 0. This is a hint to the kernel; the kernel may use a larger buffer.
For datagram sockets, it is implementation-defined whether packets larger than this size can be sent.
Timeout in milliseconds for blocking accept or read/receive operations (but not write/send operations). A timeout of 0 means no timeout. Negative timeouts are not allowed.
An InterruptedIOException
is thrown if this timeout expires.
Whether data is sent immediately on this socket. As a side-effect this could lead to low packet efficiency. The socket implementation uses the Nagle's algorithm to try to reach a higher packet efficiency if this option is disabled.
Gets the value for the specified socket option.
optID | the option identifier. |
---|
SocketException | if an error occurs reading the option value. |
---|
Sets the value of the specified socket option.
optID | the option identifier. |
---|---|
val | the value to be set for the option. |
SocketException | if an error occurs setting the option value. |
---|