package whackamole; import java.io.*; import java.net.*; import java.util.LinkedList; public class Demo { public static void main(String[] args){ System.out.println("started server"); LinkedList list = new LinkedList(); list.add(new MutInt(50)); RMI testRMI = new RMI(new MutInt(),"add",list); System.out.println("test RMI: " + testRMI); try{ final ServerSocket ss = new ServerSocket(9898); while(true){ logon(ss.accept(),testRMI); } } catch(Exception e){ throw new Error("" + e); } } protected static void logon(final Socket s, final RMI testRMI) throws IOException { (new Thread(){ public void run(){ try{ ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream()); //test 1: adds 50 itself, 5 times. resulting in 250 for(int i = 0; i < 5; i++) oos.writeObject(testRMI); //test 2: compute the sum of the first 100 integers MutInt start = new MutInt(0); for(int i = 0; i < 100; i++){ LinkedList l = new LinkedList(); l.add(new MutInt(i)); oos.writeObject(new RMI(start,"add",l)); }//end for s.close(); } catch(Exception e){ throw new Error("" + e); } } }).start(); } }// Demo