Interface SocketOptions
- All Known Implementing Classes:
DatagramSocketImpl,PlainDatagramSocketImpl,PlainServerSocketImpl,PlainSocketImpl,SocketImpl
public interface SocketOptions
SocketImpl and
DatagramSocketImpl.- See Also:
SocketImpl,DatagramSocketImpl
-
Field Summary
Fields Modifier and Type Field Description static intIP_MULTICAST_IFThis is an IPv4-only socket option whose functionality is subsumed byIP_MULTICAST_IFand not implemented on Android.static intIP_MULTICAST_IF2This integer option sets the outgoing interface for multicast packets using an interface index.static intIP_MULTICAST_LOOPThis boolean option specifies whether the local loopback of multicast packets is enabled or disabled.static intIP_TOSThis integer option specifies the value for the type-of-service field of the IPv4 header, or the traffic class field of the IPv6 header.static intSO_BINDADDRThis option does not correspond to any Unix socket option and is not implemented on Android.static intSO_BROADCASTThis boolean option can be used to enable broadcasting on datagram sockets.static intSO_KEEPALIVEThis boolean option specifies whether the kernel sends keepalive messages.static intSO_LINGERNumber of seconds to wait when closing a socket if there is still some buffered data to be sent.static intSO_OOBINLINEThis boolean option specifies whether sending TCP urgent data is supported on this socket or not.static intSO_RCVBUFThe size in bytes of a socket's receive buffer.static intSO_REUSEADDRThis boolean option specifies whether a reuse of a local address is allowed even if another socket is not yet removed by the operating system.static intSO_SNDBUFThe size in bytes of a socket's send buffer.static intSO_TIMEOUTInteger timeout in milliseconds for blocking accept or read/receive operations (but not write/send operations).static intTCP_NODELAYThis boolean option specifies whether data is sent immediately on this socket. -
Method Summary
-
Field Details
-
SO_LINGER
static final int SO_LINGERNumber 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
closereturns 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.)
- See Also:
- Constant Field Values
-
SO_TIMEOUT
static final int SO_TIMEOUTInteger 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
InterruptedIOExceptionis thrown if this timeout expires.- See Also:
- Constant Field Values
-
TCP_NODELAY
static final int TCP_NODELAYThis boolean option specifies 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.- See Also:
- Constant Field Values
-
IP_MULTICAST_IF
static final int IP_MULTICAST_IFThis is an IPv4-only socket option whose functionality is subsumed byIP_MULTICAST_IFand not implemented on Android.- See Also:
- Constant Field Values
-
SO_BINDADDR
static final int SO_BINDADDRThis option does not correspond to any Unix socket option and is not implemented on Android.- See Also:
- Constant Field Values
-
SO_REUSEADDR
static final int SO_REUSEADDRThis boolean option specifies whether a reuse of a local address is allowed even if another socket is not yet removed by the operating system. It's only available on aMulticastSocket.- See Also:
- Constant Field Values
-
SO_SNDBUF
static final int SO_SNDBUFThe 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.
- See Also:
- Constant Field Values
-
SO_RCVBUF
static final int SO_RCVBUFThe 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.
- See Also:
- Constant Field Values
-
SO_KEEPALIVE
static final int SO_KEEPALIVEThis boolean option specifies whether the kernel sends keepalive messages.- See Also:
- Constant Field Values
-
IP_TOS
static final int IP_TOSThis integer 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.
- See Also:
- Constant Field Values
-
IP_MULTICAST_LOOP
static final int IP_MULTICAST_LOOPThis boolean option specifies whether the local loopback of multicast packets is enabled or disabled. This option is enabled by default on multicast sockets. Note that the sense of this option in Java is the opposite of the underlying UnixIP_MULTICAST_LOOP. SeeMulticastSocket.setLoopbackMode(boolean).- See Also:
- Constant Field Values
-
SO_BROADCAST
static final int SO_BROADCASTThis boolean option can be used to enable broadcasting on datagram sockets.- See Also:
- Constant Field Values
-
SO_OOBINLINE
static final int SO_OOBINLINEThis boolean option specifies whether sending TCP urgent data is supported on this socket or not.- See Also:
- Constant Field Values
-
IP_MULTICAST_IF2
static final int IP_MULTICAST_IF2This integer option sets the outgoing interface for multicast packets using an interface index.- See Also:
- Constant Field Values
-
-
Method Details
-
getOption
Gets the value for the specified socket option.- Parameters:
optID- the option identifier.- Returns:
- the option value.
- Throws:
SocketException- if an error occurs reading the option value.
-
setOption
Sets the value of the specified socket option.- Parameters:
optID- the option identifier.val- the value to be set for the option.- Throws:
SocketException- if an error occurs setting the option value.
-