@Deprecated(since="16") public class Sockets extends Object
SocketOption
interface. All of the standard options defined by Socket
, ServerSocket
, and DatagramSocket
can be set this way, as well as additional or platform specific options supported by each socket type. The supportedOptions(Class)
method can be called to determine the complete set of options available (per socket type) on the current system.
When a security manager is installed, some non-standard socket options may require a security permission before being set or get. The details are specified in ExtendedSocketOptions
. No permission is required for StandardSocketOptions
.
Modifier and Type | Method | Description |
---|---|---|
static <T> T |
getOption |
Deprecated. use DatagramSocket.getOption(SocketOption) instead. |
static <T> T |
getOption |
Deprecated. use ServerSocket.getOption(SocketOption) instead. |
static <T> T |
getOption |
Deprecated. use Socket.getOption(SocketOption) instead. |
static <T> void |
setOption |
Deprecated. use DatagramSocket.setOption(SocketOption, Object) instead. |
static <T> void |
setOption |
Deprecated. use ServerSocket.setOption(SocketOption, Object) instead. |
static <T> void |
setOption |
Deprecated. use Socket.setOption(SocketOption, Object) instead. |
static Set |
supportedOptions |
Deprecated, for removal: This API element is subject to removal in a future version. |
@Deprecated(since="16") public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException
Socket.setOption(SocketOption, Object)
instead.Socket
T
- The type of the socket options
- the socketname
- The socket optionvalue
- The value of the socket option. May be null for some options.UnsupportedOperationException
- if the socket does not support the option.IllegalArgumentException
- if the value is not valid for the option.IOException
- if an I/O error occurs, or socket is closed.SecurityException
- if a security manager is set and the caller does not have any required permission.NullPointerException
- if name is null@Deprecated(since="16") public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException
Socket.getOption(SocketOption)
instead.Socket
T
- The type of the socket options
- the socketname
- The socket optionUnsupportedOperationException
- if the socket does not support the option.IOException
- if an I/O error occursSecurityException
- if a security manager is set and the caller does not have any required permission.NullPointerException
- if name is null@Deprecated(since="16") public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException
ServerSocket.setOption(SocketOption, Object)
instead.ServerSocket
T
- The type of the socket options
- the socketname
- The socket optionvalue
- The value of the socket optionUnsupportedOperationException
- if the socket does not support the option.IllegalArgumentException
- if the value is not valid for the option.IOException
- if an I/O error occursNullPointerException
- if name is nullSecurityException
- if a security manager is set and the caller does not have any required permission.@Deprecated(since="16") public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOException
ServerSocket.getOption(SocketOption)
instead.ServerSocket
T
- The type of the socket options
- the socketname
- The socket optionUnsupportedOperationException
- if the socket does not support the option.IOException
- if an I/O error occursNullPointerException
- if name is nullSecurityException
- if a security manager is set and the caller does not have any required permission.@Deprecated(since="16") public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value) throws IOException
DatagramSocket.setOption(SocketOption, Object)
instead.DatagramSocket
or MulticastSocket
T
- The type of the socket options
- the socketname
- The socket optionvalue
- The value of the socket optionUnsupportedOperationException
- if the socket does not support the option.IllegalArgumentException
- if the value is not valid for the option.IOException
- if an I/O error occursNullPointerException
- if name is nullSecurityException
- if a security manager is set and the caller does not have any required permission.@Deprecated(since="16") public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOException
DatagramSocket.getOption(SocketOption)
instead.DatagramSocket
or MulticastSocket
T
- The type of the socket options
- the socketname
- The socket optionUnsupportedOperationException
- if the socket does not support the option.IOException
- if an I/O error occursNullPointerException
- if name is nullSecurityException
- if a security manager is set and the caller does not have any required permission.@Deprecated(since="16", forRemoval=true) public static Set<SocketOption<?>> supportedOptions(Class<?> socketType)
SocketOption
s supported by the given socket type. This set may include standard options and also non standard extended options.socketType
- the type of java.net socketIllegalArgumentException
- if socketType is not a valid socket type from the java.net package.
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.net/jdk/net/Sockets.html