1. 定义 Socket 状态,SocketStatus.java
/**
* @Description: Socket 连接的状态
*/
public interface SocketStatus {
/**
* 已断开连接
*/
int SOCKET_DISCONNECTED = 0;
/**
* 正在连接
*/
int SOCKET_CONNECTING = 1;
/**
* 已连接
*/
int SOCKET_CONNECTED = 2;
/**
* 正在断开连接
*/
int SOCKET_DISCONNECTING = 3;
}
2. 创建主机地址实体类,SocketAddress.java
/**
* @Description: Socket 主机地址
*/
public class SocketAddress {
/**
* IPV4 地址
*/
private String ip;
/**
* 连接服务器端口号
*/
private int port;
/**
* 当前 IP 地址 ping 不通时的备用 IP 和端口
*/
private SocketAddress backupAddress;
public SocketAddress(String ip, int port) {
this.ip = ip;
this.port = port;
}
public St