// // Othecko 1.1 // // Steve Matuszek // Jack Freelander // University of North Carolina at Chapel Hill // // // RemoteSystem.java // Jack Freelander 1.0 // // // This class encapsulates the necessary information // needed to contact another machine (currently IP // address and port number). // import java.net.*; import java.io.*; public class RemoteSystem implements Serializable { private InetAddress address; private int port; public RemoteSystem(String machine, int port) { setAddress(machine); setPort(port); } public RemoteSystem(InetAddress ia, int port) { setAddress(ia); setPort(port); } public int getPort() { return port; } public InetAddress getAddress() { return address; } public boolean setAddress(String s) { if (s == null) { return false; } try { address = InetAddress.getByName(s); } catch(Exception e) { e.printStackTrace(); System.out.println("Failed to get address for host " + s); System.exit(0); } return (address!=null); } public boolean setAddress(InetAddress addr) { address=addr; return true; } public boolean setPort(int p) { port = p; return true; } public boolean equals(RemoteSystem rs) { if(rs==null) return false; return (rs.port==port && rs.address.equals(address)); } public String toString() { return "Address: " + address.getHostAddress() + " Port: " + port; } public Socket giveMeASocket() { try { Socket s=new Socket(address,port); return s; } catch(Exception e) { e.printStackTrace(); System.out.println("Unable to create a socket in RemoteSystem for address " + address.getHostName() + " on port " + port +"\n"); return null; } } }