forked from KNEMC/KLALB
自动获得节点地址功能
This commit is contained in:
@@ -7,17 +7,21 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Tunnel {
|
||||
private String name;
|
||||
private String ip;
|
||||
private int port;
|
||||
private IPPort ipport;
|
||||
|
||||
public Tunnel(String name, String ip, int port) {
|
||||
public Tunnel(String name, String ip, int port) throws UnknownHostException {
|
||||
super();
|
||||
this.name = name;
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
this.ipport=new IPPort(ip,port);
|
||||
}
|
||||
public Tunnel(String s) throws UnknownHostException {
|
||||
String[]t=s.split("\\$");
|
||||
name=t[0];
|
||||
ipport=new IPPort(t[1]);
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -26,24 +30,34 @@ public class Tunnel {
|
||||
this.name = name;
|
||||
}
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
return ipport.getIp().getHostAddress();
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
return ipport.getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name+"$"+ip+"$"+port;
|
||||
return name+"$"+ipport;
|
||||
}
|
||||
public Socket connectClientSocket() throws UnknownHostException, IOException {
|
||||
return new Socket(ip, port);
|
||||
return new Socket(ipport.getIp(), ipport.getPort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(ipport, name);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Tunnel other = (Tunnel) obj;
|
||||
return Objects.equals(ipport, other.ipport) && Objects.equals(name, other.name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user