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

This option specifies the interface which is used to send multicast packets. It's only available on a MulticastSocket.

Constant Value: 16 (0x00000010)

public static final int IP_MULTICAST_IF2

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.

Constant Value: 31 (0x0000001f)

public static final int IP_MULTICAST_LOOP

This option specifies whether the local loopback of multicast packets is enabled or disabled. This option is enabled by default on multicast sockets.

Constant Value: 18 (0x00000012)

public static final int IP_TOS

This option specifies the value for the Type-of-Service (TOS) field of the IP header.

Constant Value: 3 (0x00000003)

public static final int SO_BINDADDR

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.

Constant Value: 15 (0x0000000f)

public static final int SO_BROADCAST

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

Constant Value: 32 (0x00000020)

public static final int SO_KEEPALIVE

This option specifies whether socket implementations can send keepalive messages if no data has been sent for a longer time.

Constant Value: 8 (0x00000008)

public static final 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. 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 <= 65535.

Constant Value: 128 (0x00000080)

public static final int SO_OOBINLINE

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

Buffer size of the incoming channel.

Constant Value: 4098 (0x00001002)

public static final 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. It's only available on a MulticastSocket.

Constant Value: 4 (0x00000004)

public static final int SO_SNDBUF

Buffer size of the outgoing channel.

Constant Value: 4097 (0x00001001)

public static final int SO_TIMEOUT

Timeout for blocking operations. The argument value is specified in milliseconds. An InterruptedIOException is thrown if this timeout expires.

Constant Value: 4102 (0x00001006)

public static final 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. 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)

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)

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.