Class Sockets
java.lang.Object
jdk.net.Sockets
Deprecated.
Java SE 9 added standard methods to set/get socket options, and retrieve the per-Socket
supported options effectively rendering this API redundant. Please refer to the corresponding
socket's class for the equivalent method to set/get a socket option or retrieve available socket options.
Defines static methods to set and get socket options defined by the
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.
- Since:
- 1.8
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TgetOption(DatagramSocket s, SocketOption<T> name) Deprecated.useDatagramSocket.getOption(SocketOption)instead.static <T> TgetOption(ServerSocket s, SocketOption<T> name) Deprecated.useServerSocket.getOption(SocketOption)instead.static <T> TgetOption(Socket s, SocketOption<T> name) Deprecated.useSocket.getOption(SocketOption)instead.static <T> voidsetOption(DatagramSocket s, SocketOption<T> name, T value) Deprecated.useDatagramSocket.setOption(SocketOption, Object)instead.static <T> voidsetOption(ServerSocket s, SocketOption<T> name, T value) Deprecated.useServerSocket.setOption(SocketOption, Object)instead.static <T> voidsetOption(Socket s, SocketOption<T> name, T value) Deprecated.useSocket.setOption(SocketOption, Object)instead.static Set<SocketOption<?>> supportedOptions(Class<?> socketType) Deprecated, for removal: This API element is subject to removal in a future version.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Method Details
-
setOption
@Deprecated(since="16") public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException Deprecated.useSocket.setOption(SocketOption, Object)instead.Sets the value of a socket option on aSocket- Type Parameters:
T- The type of the socket option- Parameters:
s- the socketname- The socket optionvalue- The value of the socket option. May be null for some options.- Throws:
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.NullPointerException- if name is null- See Also:
-
getOption
@Deprecated(since="16") public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException Deprecated.useSocket.getOption(SocketOption)instead.Returns the value of a socket option from aSocket- Type Parameters:
T- The type of the socket option- Parameters:
s- the socketname- The socket option- Returns:
- The value of the socket option.
- Throws:
UnsupportedOperationException- if the socket does not support the option.IOException- if an I/O error occursNullPointerException- if name is null- See Also:
-
setOption
@Deprecated(since="16") public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException Deprecated.useServerSocket.setOption(SocketOption, Object)instead.Sets the value of a socket option on aServerSocket- Type Parameters:
T- The type of the socket option- Parameters:
s- the socketname- The socket optionvalue- The value of the socket option- Throws:
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 occursNullPointerException- if name is null- See Also:
-
getOption
@Deprecated(since="16") public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOException Deprecated.useServerSocket.getOption(SocketOption)instead.Returns the value of a socket option from aServerSocket- Type Parameters:
T- The type of the socket option- Parameters:
s- the socketname- The socket option- Returns:
- The value of the socket option.
- Throws:
UnsupportedOperationException- if the socket does not support the option.IOException- if an I/O error occursNullPointerException- if name is null- See Also:
-
setOption
@Deprecated(since="16") public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value) throws IOException Deprecated.useDatagramSocket.setOption(SocketOption, Object)instead.Sets the value of a socket option on aDatagramSocketorMulticastSocket- Type Parameters:
T- The type of the socket option- Parameters:
s- the socketname- The socket optionvalue- The value of the socket option- Throws:
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 occursNullPointerException- if name is null- See Also:
-
getOption
@Deprecated(since="16") public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOException Deprecated.useDatagramSocket.getOption(SocketOption)instead.Returns the value of a socket option from aDatagramSocketorMulticastSocket- Type Parameters:
T- The type of the socket option- Parameters:
s- the socketname- The socket option- Returns:
- The value of the socket option.
- Throws:
UnsupportedOperationException- if the socket does not support the option.IOException- if an I/O error occursNullPointerException- if name is null- See Also:
-
supportedOptions
@Deprecated(since="16", forRemoval=true) public static Set<SocketOption<?>> supportedOptions(Class<?> socketType) Deprecated, for removal: This API element is subject to removal in a future version.Returns a set ofSocketOptions supported by the given socket type. This set may include standard options and also non standard extended options.- Parameters:
socketType- the type of java.net socket- Returns:
- A set of socket options
- Throws:
IllegalArgumentException- if socketType is not a valid socket type from the java.net package.
-