public class SocketUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
close(Socket socket)
关闭socket
|
static boolean |
isConnected(Socket socket)
是否连接状态
|
static int |
read(Socket socket,
byte[] data)
读取数据
|
static int |
read(Socket socket,
byte[] data,
int offset,
int length)
读取数据
|
static int |
read(Socket socket,
byte[] data,
int offset,
int length,
int maxLength)
读取数据
|
static int |
read(Socket socket,
byte[] data,
int offset,
int length,
int maxLength,
int timeout)
读取数据
|
static int |
read(Socket socket,
byte[] data,
int offset,
int length,
int maxLength,
int timeout,
boolean waitForMore)
读取数据
|
static void |
write(Socket socket,
byte[] data)
写入数据
|
static void |
write(Socket socket,
byte[] data,
int offset,
int length)
写入数据
|
static void |
write(Socket socket,
byte[] data,
int offset,
int length,
int maxLength)
写入数据
|
public static void close(Socket socket) throws IOException
socket - socket对象IOException - IO异常public static boolean isConnected(Socket socket)
socket - socket对象public static int read(Socket socket, byte[] data) throws IOException
socket - socket对象data - 字节数组IOException - IO异常public static int read(Socket socket, byte[] data, int offset, int length) throws IOException
socket - socket对象data - 字节数组offset - 偏移量length - 读取长度IOException - IO异常public static int read(Socket socket, byte[] data, int offset, int length, int maxLength) throws IOException
socket - socket对象data - 字节数组offset - 偏移量length - 读取长度maxLength - 单次通信允许的对最大长度IOException - IO异常public static int read(Socket socket, byte[] data, int offset, int length, int maxLength, int timeout) throws IOException
socket - socket对象data - 字节数组offset - 偏移量length - 读取长度maxLength - 单次通信允许的对最大长度timeout - 超时时间,0:没有超时时间IOException - IO异常public static int read(Socket socket, byte[] data, int offset, int length, int maxLength, int timeout, boolean waitForMore) throws IOException
socket - socket对象data - 字节数组offset - 偏移量length - 读取长度maxLength - 单次通信允许的对最大长度timeout - 超时时间,0:没有超时时间,无限等waitForMore - 若数据不够,是否等待,等待更多数据,大部分都是不等待的,等待都适用于分包粘包的情况IOException - IO异常public static void write(Socket socket, byte[] data) throws IOException
socket - socket对象data - 字节数组IOException - IO异常public static void write(Socket socket, byte[] data, int offset, int length) throws IOException
socket - socket对象data - 字节数组offset - 偏移量length - 写入长度IOException - IO异常public static void write(Socket socket, byte[] data, int offset, int length, int maxLength) throws IOException
socket - socket对象data - 字节数组offset - 偏移量length - 写入长度maxLength - 单次通信允许的对最大长度IOException - IO异常Copyright © 2024. All rights reserved.