Package java.net

Interface SocketOptions

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int IP_MULTICAST_IF
      This is an IPv4-only socket option whose functionality is subsumed by IP_MULTICAST_IF2 and not implemented on Android.
      static int IP_MULTICAST_IF2
      This integer option sets the outgoing interface for multicast packets using an interface index.
      static int IP_MULTICAST_LOOP
      This boolean option specifies whether the local loopback of multicast packets is enabled or disabled.
      static 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.
      static int SO_BINDADDR
      This option does not correspond to any Unix socket option and is not implemented on Android.
      static int SO_BROADCAST
      This boolean option can be used to enable or disable broadcasting on datagram sockets.
      static int SO_KEEPALIVE
      This boolean option specifies whether the kernel sends keepalive messages on connection-oriented sockets.
      static int SO_LINGER
      Number of seconds to wait when closing a socket if there is still some buffered data to be sent.
      static int SO_OOBINLINE
      This boolean option specifies whether sending TCP urgent data is supported on this socket or not.
      static int SO_RCVBUF
      The size in bytes of a socket's receive buffer.
      static int SO_REUSEADDR
      This boolean option specifies whether a reuse of a local address is allowed when another socket has not yet been removed by the operating system.
      static int SO_REUSEPORT  
      static int SO_SNDBUF
      The size in bytes of a socket's send buffer.
      static int SO_TIMEOUT
      Integer timeout in milliseconds for blocking accept or read/receive operations (but not write/send operations).
      static int TCP_NODELAY
      This boolean option specifies whether data is sent immediately on this socket or buffered.
    • Field Detail

      • SO_LINGER

        static final int SO_LINGER
        Number of seconds to wait when closing a socket if there is still some buffered data to be sent.

        The option can be set to disabled using setOption(int, Object) with a value of Boolean.FALSE.

        If this option is set to 0, the TCP socket is closed forcefully and the call to close returns immediately. If this option is disabled, closing a socket will return immediately and the close will be handled in the background.

        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 numeric values for this option are in the range 0 to 65535 inclusive. (Larger timeouts will be treated as 65535s timeouts; roughly 18 hours.)

        This option is intended for use with sockets in blocking mode. The behavior of this option for non-blocking sockets is undefined.

        See Also:
        Constant Field Values
      • SO_TIMEOUT

        static final int SO_TIMEOUT
        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.

        See Also:
        Constant Field Values
      • TCP_NODELAY

        static final int TCP_NODELAY
        This boolean option specifies whether data is sent immediately on this socket or buffered.

        If set to Boolean.TRUE the Nagle algorithm is disabled and there is no buffering. This could lead to low packet efficiency. When set to Boolean.FALSE the the socket implementation uses buffering to try to reach a higher packet efficiency.

        See RFC 1122: Requirements for Internet Hosts -- Communication Layers for more information about buffering and the Nagle algorithm.

        See Also:
        Constant Field Values
      • IP_MULTICAST_IF

        static final int IP_MULTICAST_IF
        This is an IPv4-only socket option whose functionality is subsumed by IP_MULTICAST_IF2 and not implemented on Android.
        See Also:
        Constant Field Values
      • SO_BINDADDR

        static final int SO_BINDADDR
        This 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_REUSEADDR
        This boolean option specifies whether a reuse of a local address is allowed when another socket has not yet been removed by the operating system.

        For connection-oriented sockets, if this option is disabled and if there is another socket in state TIME_WAIT on a given address then another socket binding to that address would fail. Setting this value after a socket is bound has no effect.

        For datagram sockets this option determines whether several sockets can listen on the same address; when enabled each socket will receive a copy of the datagram.

        See RFC 793: Transmission Control Protocol for more information about socket re-use.

        See Also:
        Constant Field Values
      • SO_SNDBUF

        static final int SO_SNDBUF
        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.

        See Also:
        Constant Field Values
      • SO_RCVBUF

        static final int SO_RCVBUF
        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.

        See RFC1323: TCP Extensions for High Performance for more information about TCP/IP buffering.

        See Also:
        Constant Field Values
      • IP_TOS

        static final 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. 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
      • SO_BROADCAST

        static final int SO_BROADCAST
        This boolean option can be used to enable or disable broadcasting on datagram sockets. This option must be enabled to send broadcast messages. The default value is false.
        See Also:
        Constant Field Values
      • SO_OOBINLINE

        static final int SO_OOBINLINE
        This boolean option specifies whether sending TCP urgent data is supported on this socket or not.
        See Also:
        Constant Field Values
    • Method Detail

      • getOption

        Object getOption​(int optID)
                  throws SocketException
        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

        void setOption​(int optID,
                       Object val)
                throws SocketException
        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.