1 23 package fr.dyade.aaa.util; 24 25 import java.net.InetAddress ; 26 import java.net.UnknownHostException ; 27 28 31 public class SocketAddress { 32 33 private String hostname; 34 35 private InetAddress addr; 36 37 private int port; 38 39 45 public SocketAddress(String hostname, int port) { 46 this.hostname = hostname; 47 try { 48 addr = InetAddress.getByName(this.hostname); 49 } catch (UnknownHostException exc) { 50 addr = null; 51 } 52 this.port = port; 53 } 54 55 61 public InetAddress resetAddr() { 62 try { 63 addr = InetAddress.getByName(getHostname()); 64 } catch (UnknownHostException exc) { 65 addr = null; 66 } 67 return addr; 68 } 69 70 75 public int getPort() { 76 return port; 77 } 78 79 84 public String getHostname() { 85 return hostname; 86 } 87 88 93 public InetAddress getAddress() { 94 return addr; 95 } 96 97 104 public boolean equals(Object obj) { 105 if (obj == null || !(obj instanceof SocketAddress)) 106 return false; 107 SocketAddress sa = (SocketAddress) obj; 108 109 if ((hostname.equals(sa.hostname)) && 110 (addr != null && addr.equals(sa.addr)) && 111 (port == sa.port)) 112 return true; 113 return false; 114 } 115 116 121 public String toString() { 122 StringBuffer strBuf = new StringBuffer (); 123 strBuf.append("(").append(super.toString()); 124 strBuf.append(",hostname=").append(hostname); 125 strBuf.append(",port=").append(port); 126 strBuf.append(",addr=").append(addr); 127 strBuf.append(")"); 128 return strBuf.toString(); 129 } 130 } 131 | Popular Tags |