public class NetUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.net.ServerSocket |
closeSilently(java.net.ServerSocket socket)
Close a server socket and ignore any exceptions.
|
static java.net.Socket |
createLoopbackSocket(int port,
boolean ssl)
Create a loopback socket (a socket that is connected to localhost) on
this port.
|
static java.net.ServerSocket |
createServerSocket(int port,
boolean ssl)
Create a server socket.
|
static java.net.Socket |
createSocket(java.net.InetAddress address,
int port,
boolean ssl)
Create a client socket that is connected to the given address and port.
|
static java.net.Socket |
createSocket(java.lang.String server,
int defaultPort,
boolean ssl)
Create a client socket that is connected to the given address and port.
|
static java.lang.String |
getHostName(java.lang.String localAddress)
Get the host name of a local address, if available.
|
static java.lang.String |
getLocalAddress()
Get the local host address as a string.
|
static boolean |
isLocalAddress(java.net.Socket socket)
Check if a socket is connected to a local address.
|
public static java.net.Socket createLoopbackSocket(int port,
boolean ssl)
throws java.io.IOException
port - the portssl - if SSL should be usedjava.io.IOExceptionpublic static java.net.Socket createSocket(java.lang.String server,
int defaultPort,
boolean ssl)
throws java.io.IOException
server - to connect to (including an optional port)defaultPort - the default port (if not specified in the server
address)ssl - if SSL should be usedjava.io.IOExceptionpublic static java.net.Socket createSocket(java.net.InetAddress address,
int port,
boolean ssl)
throws java.io.IOException
address - the address to connect toport - the portssl - if SSL should be usedjava.io.IOExceptionpublic static java.net.ServerSocket createServerSocket(int port,
boolean ssl)
This system change is effectively permanent for the lifetime of the JVM.
port - the port to listen onssl - if SSL should be usedCipherFactory.removeAnonFromLegacyAlgorithms()public static boolean isLocalAddress(java.net.Socket socket)
throws java.net.UnknownHostException
socket - the socketjava.net.UnknownHostExceptionpublic static java.net.ServerSocket closeSilently(java.net.ServerSocket socket)
socket - the socketpublic static java.lang.String getLocalAddress()
public static java.lang.String getHostName(java.lang.String localAddress)
localAddress - the local address