APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.net

public Class Sockets

extends Object
Class Inheritance
Annotations
@Deprecated
since:16
Imports
jdk.net.ExtendedSocketOptions.PlatformSocketOptions, java.io.IOException, java.net.DatagramSocket, .MulticastSocket, .ServerSocket, .Socket, .SocketOption, .StandardSocketOptions, java.util.Collections, .HashMap, .HashSet, .Map, .Set

Deprecated

since 16.

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 java.net.SocketOption interface. All of the standard options defined by java.net.Socket, java.net.ServerSocket, and java.net.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
java.nio.channels.NetworkChannel

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Sockets.KeepAliveOptions

Tells whether TCP_KEEPALIVE options are supported.

pack-priv static class
Sockets.QuickAck

Tells whether TCP_QUICKACK is supported.

Field Summary

Modifier and TypeField and Description
private static volatile boolean
private static volatile boolean
private static final Map<Class<?>, Set<SocketOption<?>>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
checkValueType(Object value, Class<?> type)

public static <
The type of the socket option
T
>
T

Returns:

The value of the socket option.
getOption
(Socket
the socket
s
,
SocketOption<T>
The socket option
name
)
Deprecated since 16. use java.net.Socket#getOption(SocketOption) instead.

Returns the value of a socket option from a java.net.Socket

public static <
The type of the socket option
T
>
T

Returns:

The value of the socket option.
getOption
(ServerSocket
the socket
s
,
SocketOption<T>
The socket option
name
)
Deprecated since 16. use java.net.ServerSocket#getOption(SocketOption) instead.

Returns the value of a socket option from a java.net.ServerSocket

public static <
The type of the socket option
T
>
T

Returns:

The value of the socket option.
getOption
(DatagramSocket
the socket
s
,
SocketOption<T>
The socket option
name
)
Deprecated since 16. use java.net.DatagramSocket#getOption(SocketOption) instead.

Returns the value of a socket option from a java.net.DatagramSocket or java.net.MulticastSocket

pack-priv static boolean
isReusePortAvailable()

Tells whether SO_REUSEPORT is supported.

private static Map<Class<?>, Set<SocketOption<?>>>
public static <
The type of the socket option
T
>
void
setOption(Socket
the socket
s
,
SocketOption<T>
The socket option
name
,
T
The value of the socket option. May be null for some options.
value
)
Deprecated since 16. use java.net.Socket#setOption(SocketOption, Object) instead.

Sets the value of a socket option on a java.net.Socket

public static <
The type of the socket option
T
>
void
setOption(ServerSocket
the socket
s
,
SocketOption<T>
The socket option
name
,
T
The value of the socket option
value
)
Deprecated since 16. use java.net.ServerSocket#setOption(SocketOption, Object) instead.

Sets the value of a socket option on a java.net.ServerSocket

public static <
The type of the socket option
T
>
void
setOption(DatagramSocket
the socket
s
,
SocketOption<T>
The socket option
name
,
T
The value of the socket option
value
)

Sets the value of a socket option on a java.net.DatagramSocket or java.net.MulticastSocket

public static Set<SocketOption<?>>

Returns:

A set of socket options
supportedOptions
(Class<?>
the type of java.net socket
socketType
)

Returns a set of java.net.SocketOptions supported by the given socket type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkedReusePortback to summary
private static volatile boolean checkedReusePort
isReusePortAvailableback to summary
private static volatile boolean isReusePortAvailable
optionsback to summary
private static final Map<Class<?>, Set<SocketOption<?>>> options

Constructor Detail

Socketsback to summary
private Sockets()

Method Detail

checkValueTypeback to summary
private static void checkValueType(Object value, Class<?> type)
getOptionback to summary
public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException

Deprecated

since 16.

use java.net.Socket#getOption(SocketOption) instead.

Returns the value of a socket option from a java.net.Socket

Parameters
<T>
The type of the socket option
s:Socket

the socket

name:SocketOption<T>

The socket option

Returns:T

The value of the socket option.

Annotations
@Deprecated
since:16
Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if the socket does not support the option.
NullPointerException:
if name is null
See Also
java.net.StandardSocketOptions
getOptionback to summary
public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOException

Deprecated

since 16.

use java.net.ServerSocket#getOption(SocketOption) instead.

Returns the value of a socket option from a java.net.ServerSocket

Parameters
<T>
The type of the socket option
s:ServerSocket

the socket

name:SocketOption<T>

The socket option

Returns:T

The value of the socket option.

Annotations
@Deprecated
since:16
Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if the socket does not support the option.
NullPointerException:
if name is null
See Also
java.net.StandardSocketOptions
getOptionback to summary
public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOException

Deprecated

since 16.

use java.net.DatagramSocket#getOption(SocketOption) instead.

Returns the value of a socket option from a java.net.DatagramSocket or java.net.MulticastSocket

Parameters
<T>
The type of the socket option
s:DatagramSocket

the socket

name:SocketOption<T>

The socket option

Returns:T

The value of the socket option.

Annotations
@Deprecated
since:16
Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if the socket does not support the option.
NullPointerException:
if name is null
See Also
java.net.StandardSocketOptions
isReusePortAvailableback to summary
pack-priv static boolean isReusePortAvailable()

Tells whether SO_REUSEPORT is supported.

optionSetsback to summary
private static Map<Class<?>, Set<SocketOption<?>>> optionSets()
setOptionback to summary
public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException

Deprecated

since 16.

use java.net.Socket#setOption(SocketOption, Object) instead.

Sets the value of a socket option on a java.net.Socket

Parameters
<T>
The type of the socket option
s:Socket

the socket

name:SocketOption<T>

The socket option

value:T

The value of the socket option. May be null for some options.

Annotations
@Deprecated
since:16
Exceptions
IOException:
if an I/O error occurs, or socket is closed.
UnsupportedOperationException:
if the socket does not support the option.
IllegalArgumentException:
if the value is not valid for the option.
NullPointerException:
if name is null
See Also
java.net.StandardSocketOptions
setOptionback to summary
public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException

Sets the value of a socket option on a java.net.ServerSocket

Parameters
<T>
The type of the socket option
s:ServerSocket

the socket

name:SocketOption<T>

The socket option

value:T

The value of the socket option

Annotations
@Deprecated
since:16
Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if the socket does not support the option.
IllegalArgumentException:
if the value is not valid for the option.
NullPointerException:
if name is null
See Also
java.net.StandardSocketOptions
setOptionback to summary
public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value) throws IOException

Sets the value of a socket option on a java.net.DatagramSocket or java.net.MulticastSocket

Parameters
<T>
The type of the socket option
s:DatagramSocket

the socket

name:SocketOption<T>

The socket option

value:T

The value of the socket option

Annotations
@Deprecated
since:16
Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if the socket does not support the option.
IllegalArgumentException:
if the value is not valid for the option.
NullPointerException:
if name is null
See Also
java.net.StandardSocketOptions
supportedOptionsback to summary
public static Set<SocketOption<?>> supportedOptions(Class<?> socketType)

Returns a set of java.net.SocketOptions supported by the given socket type. This set may include standard options and also non standard extended options.

Parameters
socketType:Class<?>

the type of java.net socket

Returns:Set<SocketOption<?>>

A set of socket options

Annotations
@Deprecated
since:16
forRemoval:true
Exceptions
IllegalArgumentException:
if socketType is not a valid socket type from the java.net package.
jdk.net back to summary

pack-priv Class Sockets.KeepAliveOptions

extends Object
Class Inheritance

Tells whether TCP_KEEPALIVE options are supported.

Field Summary

Modifier and TypeField and Description
pack-priv static final boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AVAILABLEback to summary
pack-priv static final boolean AVAILABLE

Constructor Detail

KeepAliveOptionsback to summary
pack-priv KeepAliveOptions()
jdk.net back to summary

pack-priv Class Sockets.QuickAck

extends Object
Class Inheritance

Tells whether TCP_QUICKACK is supported.

Field Summary

Modifier and TypeField and Description
pack-priv static final boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

availableback to summary
pack-priv static final boolean available

Constructor Detail

QuickAckback to summary
pack-priv QuickAck()