try{
// create a server socket on port 9000
ServerSocket serverSocket = new ServerSocket(9000);
// wait for and obtain a socket connection from stub
Socket socket = serverSocket.accept();
while(socket != null){
// create an input stream to receive requests from stub
ObjectInputStream inStream
= new ObjectInputStream(socket.getInputStream());
// Read next method request from stub. Block until request is
// sent.
String method = (String)inStream.readObject();
// Evalute the type of method requested
if(method.equals("age")){
// invoke business method on server object
int age = myServer.getAge();
// create an output stream to send return values back to
// stub.
ObjectOutputStream outStream
= new ObjectOutputStream(socket.getOutputStream());
// send results back to stub
outStream.writeInt(age);
outStream.flush();
}else if(method.equals("name")){
// invoke business method on server object
String name = myServer.getName();
// create an output stream to send return values back to
// the stub.
ObjectOutputStream outStream
= new ObjectOutputStream(socket.getOutputStream());
// send results back to stub
outStream.writeObject(name);
outStream.flush();
}
}
}catch(Throwable t) {t.printStackTrace();System.exit(0); }