to top
Android APIs
Added in API level 1
public interface

SocketOptions

java.net.SocketOptions
Known Indirect Subclasses

Class Overview

Defines an interface for socket implementations to get and set socket options. It is implemented by the classes SocketImpl and DatagramSocketImpl.

Summary

Constants
int IP_MULTICAST_IF This is an IPv4-only socket option whose functionality is subsumed by IP_MULTICAST_IF and not implemented on Android.
int IP_MULTICAST_IF2 This integer option sets the outgoing interface for multicast packets using an interface index.
int IP_MULTICAST_LOOP This boolean option specifies whether the local loopback of multicast packets is enabled or disabled.
int IP_TOS This integer 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 does not correspond to any Unix socket option and is not implemented on Android.
int SO_BROADCAST This boolean option can be used to enable broadcasting on datagram sockets.
int SO_KEEPALIVE This boolean option specifies whether the kernel sends keepalive messages.
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 boolean option specifies whether a reuse of a local address is allowed even if another 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 Integer timeout in milliseconds for blocking accept or read/receive operations (but not write/send operations).
int TCP_NODELAY This boolean option specifies whether data is sent immediately on this socket.
Public Methods
abstract Object getOption(int optID)
Gets the value for the specified socket option.
abstract void setOption(int optID, Object val)
Sets the value of the specified socket option.

Constants

public static final int IP_MULTICAST_IF

Added in API level 1

This is an IPv4-only socket option whose functionality is subsumed by IP_MULTICAST_IF and not implemented on Android.

Constant Value: 16 (0x00000010)

public static final int IP_MULTICAST_IF2

Added in API level 1

This integer option sets the outgoing interface for multicast packets using an interface index.

Constant Value: 31 (0x0000001f)

public static final int IP_MULTICAST_LOOP

Added in API level 1

This 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 Unix IP_MULTICAST_LOOP. See setLoopbackMode(boolean).

Constant Value: 18 (0x00000012)

public static final int IP_TOS

Added in API level 1

This 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.

Constant Value: 3 (0x00000003)

public static final int SO_BINDADDR

Added in API level 1

This option does not correspond to any Unix socket option and is not implemented on Android.

Constant Value: 15 (0x0000000f)

public static final int SO_BROADCAST

Added in API level 1

This boolean option can be used to enable broadcasting on datagram sockets.

Constant Value: 32 (0x00000020)

public static final int SO_KEEPALIVE

Added in API level 1

This boolean option specifies whether the kernel sends keepalive messages.

Constant Value: 8 (0x00000008)

public static final int SO_LINGER

Added in API level 1

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.)

Constant Value: 128 (0x00000080)

public static final int SO_OOBINLINE

Added in API level 1

This boolean option specifies whether sending TCP urgent data is supported on this socket or not.

Constant Value: 4099 (0x00001003)

public static final int SO_RCVBUF

Added in API level 1

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.

Constant Value: 4098 (0x00001002)

public static final int SO_REUSEADDR

Added in API level 1

This 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 a MulticastSocket.

Constant Value: 4 (0x00000004)

public static final int SO_SNDBUF

Added in API level 1

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.

Constant Value: 4097 (0x00001001)

public static final int SO_TIMEOUT

Added in API level 1

Integer 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.

Constant Value: 4102 (0x00001006)

public static final int TCP_NODELAY

Added in API level 1

This 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.

Constant Value: 1 (0x00000001)

Public Methods

public abstract Object getOption (int optID)

Added in API level 1

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.

public abstract void setOption (int optID, Object val)

Added in 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.
Throws
SocketException if an error occurs setting the option value.