import java.io.IOException; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.net.Socket; public class Person_Stub implements Person { Socket socket; public Person_Stub() throws Throwable { // Create a network connection to the skeleton. // Replace "myhost" with your own IP Address of your computer. String host = "localhost"; //-> 127.0.0.1 int port = 9000; socket = new Socket("localhost",port); System.out.println("\n Person_Stub: open connection to host: "+host+" port:"+port); } public int getAge() throws Throwable{ // When this method is invoked, stream the method name to the // skeleton. ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream()); outStream.writeObject("age"); outStream.flush(); ObjectInputStream inStream = new ObjectInputStream(socket.getInputStream()); return inStream.readInt(); } public String getName() throws Throwable { // When this method is invoked, stream the method name to the // skeleton. ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream()); outStream.writeObject("name"); outStream.flush(); ObjectInputStream inStream = new ObjectInputStream(socket.getInputStream()); return (String)inStream.readObject(); } public void terminate() throws Throwable { // When this method is invoked, stream the method name to the // skeleton. ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream()); outStream.writeObject("fim"); outStream.flush(); } public void finalize() { try { socket.close(); } catch( IOException e ) { System.out.println("\n Person_Stub: closing connection to host "); } } }