public class NetUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static ServerSocket |
closeSilently(ServerSocket socket)
Close a server socket and ignore any exceptions.
|
static Socket |
createLoopbackSocket(int port,
boolean ssl)
Create a loopback socket (a socket that is connected to localhost) on
this port.
|
static ServerSocket |
createServerSocket(int port,
boolean ssl)
Create a server socket.
|
static Socket |
createSocket(InetAddress address,
int port,
boolean ssl)
Create a client socket that is connected to the given address and port.
|
static Socket |
createSocket(String server,
int defaultPort,
boolean ssl)
Create a client socket that is connected to the given address and port.
|
static String |
getHostName(String localAddress)
Get the host name of a local address, if available.
|
static String |
getLocalAddress()
Get the local host address as a string.
|
static boolean |
isLocalAddress(Socket socket)
Check if a socket is connected to a local address.
|
public static Socket createLoopbackSocket(int port, boolean ssl) throws IOException
port - the portssl - if SSL should be usedIOExceptionpublic static Socket createSocket(String server, int defaultPort, boolean ssl) throws 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 usedIOExceptionpublic static Socket createSocket(InetAddress address, int port, boolean ssl) throws IOException
address - the address to connect toport - the portssl - if SSL should be usedIOExceptionpublic static 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(Socket socket) throws UnknownHostException
socket - the socketUnknownHostExceptionpublic static ServerSocket closeSilently(ServerSocket socket)
socket - the socketpublic static String getLocalAddress()
Copyright © 2017. All rights reserved.