public class SocketUtil extends Object
Constructor and Description |
---|
SocketUtil() |
Modifier and Type | Method and Description |
---|---|
static Socket |
connect(InetSocketAddress address,
int connectionTimeout)
创建Socket并连接到指定地址的服务器
|
static Socket |
connect(String hostname,
int port)
创建Socket并连接到指定地址的服务器
|
static Socket |
connect(String hostname,
int port,
int connectionTimeout)
创建Socket并连接到指定地址的服务器
|
static SocketAddress |
getRemoteAddress(AsynchronousSocketChannel channel)
获取远程端的地址信息,包括host和端口
null表示channel为null或者远程主机未连接 |
static boolean |
isConnected(AsynchronousSocketChannel channel)
远程主机是否处于连接状态
通过判断远程地址获取成功与否判断 |
public static SocketAddress getRemoteAddress(AsynchronousSocketChannel channel) throws IORuntimeException
channel
- AsynchronousSocketChannel
IORuntimeException
- IO异常public static boolean isConnected(AsynchronousSocketChannel channel) throws IORuntimeException
channel
- AsynchronousSocketChannel
IORuntimeException
- IO异常public static Socket connect(String hostname, int port) throws IORuntimeException
hostname
- 地址port
- 端口Socket
IORuntimeException
- IO异常public static Socket connect(String hostname, int port, int connectionTimeout) throws IORuntimeException
hostname
- 地址port
- 端口connectionTimeout
- 连接超时Socket
IORuntimeException
- IO异常public static Socket connect(InetSocketAddress address, int connectionTimeout) throws IORuntimeException
address
- 地址connectionTimeout
- 连接超时Socket
IORuntimeException
- IO异常Copyright © 2024. All rights reserved.