- java.lang.Object
- 
- jdk.net.Sockets
 
- 
 public class Sockets extends Object Defines static methods to set and get socket options defined by theSocketOptioninterface. All of the standard options defined bySocket,ServerSocket, andDatagramSocketcan 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 forStandardSocketOptions.- See Also:
- NetworkChannel
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TgetOption(DatagramSocket s, SocketOption<T> name)Returns the value of a socket option from aDatagramSocketorMulticastSocketstatic <T> TgetOption(ServerSocket s, SocketOption<T> name)Returns the value of a socket option from aServerSocketstatic <T> TgetOption(Socket s, SocketOption<T> name)Returns the value of a socket option from aSocketstatic <T> voidsetOption(DatagramSocket s, SocketOption<T> name, T value)Sets the value of a socket option on aDatagramSocketorMulticastSocketstatic <T> voidsetOption(ServerSocket s, SocketOption<T> name, T value)Sets the value of a socket option on aServerSocketstatic <T> voidsetOption(Socket s, SocketOption<T> name, T value)Sets the value of a socket option on aSocketstatic Set<SocketOption<?>>supportedOptions(Class<?> socketType)Returns a set ofSocketOptions supported by the given socket type.
 
- 
- 
- 
Method Detail- 
setOptionpublic static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException Sets the value of a socket option on aSocket- Parameters:
- s- the socket
- name- The socket option
- value- 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.
- SecurityException- if a security manager is set and the caller does not have any required permission.
- NullPointerException- if name is null
- See Also:
- StandardSocketOptions
 
 - 
getOptionpublic static <T> T getOption(Socket s, SocketOption<T> name) throws IOException Returns the value of a socket option from aSocket- Parameters:
- s- the socket
- name- 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 occurs
- SecurityException- if a security manager is set and the caller does not have any required permission.
- NullPointerException- if name is null
- See Also:
- StandardSocketOptions
 
 - 
setOptionpublic static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException Sets the value of a socket option on aServerSocket- Parameters:
- s- the socket
- name- The socket option
- value- 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 occurs
- NullPointerException- if name is null
- SecurityException- if a security manager is set and the caller does not have any required permission.
- See Also:
- StandardSocketOptions
 
 - 
getOptionpublic static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOException Returns the value of a socket option from aServerSocket- Parameters:
- s- the socket
- name- 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 occurs
- NullPointerException- if name is null
- SecurityException- if a security manager is set and the caller does not have any required permission.
- See Also:
- StandardSocketOptions
 
 - 
setOptionpublic static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value) throws IOException Sets the value of a socket option on aDatagramSocketorMulticastSocket- Parameters:
- s- the socket
- name- The socket option
- value- 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 occurs
- NullPointerException- if name is null
- SecurityException- if a security manager is set and the caller does not have any required permission.
- See Also:
- StandardSocketOptions
 
 - 
getOptionpublic static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOException Returns the value of a socket option from aDatagramSocketorMulticastSocket- Parameters:
- s- the socket
- name- 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 occurs
- NullPointerException- if name is null
- SecurityException- if a security manager is set and the caller does not have any required permission.
- See Also:
- StandardSocketOptions
 
 - 
supportedOptionspublic static Set<SocketOption<?>> supportedOptions(Class<?> socketType) 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
- Throws:
- IllegalArgumentException- if socketType is not a valid socket type from the java.net package.
 
 
- 
 
-