/Users/lyon/j4p/src/net/compute/AutoServerLyon.java

1    package net.compute; 
2     
3    import java.io.IOException; 
4    import java.io.ObjectInputStream; 
5    import java.io.ObjectOutputStream; 
6    import java.net.ServerSocket; 
7    import java.net.Socket; 
8    import classUtils.dumper.ByteCodeContainer; 
9     
10    
11   public class AutoServerLyon implements Runnable { 
12       public final static int PORT = 8000; 
13    
14       public static void main(String args[]) { 
15           Thread serverThread = new Thread(new AutoServerLyon()); 
16           serverThread.start(); 
17           try { 
18               Thread.sleep(1000); 
19           } catch (InterruptedException e) { 
20           } 
21       } 
22    
23       public void run() { 
24           try { 
25               ServerSocket ss = 
26                       new ServerSocket(PORT); 
27               while (true) { 
28                   System.out.println("autoServerThread waiting"); 
29                   Socket socket = ss.accept(); 
30                   (new AutoServerThread1(socket)).start(); 
31               } 
32           } catch (IOException e) { 
33               e.printStackTrace(); 
34           } 
35       } 
36   } 
37    
38   class AutoServerThread extends 
39           Thread { 
40       private ObjectInputStream ois; 
41       private ObjectOutputStream oos; 
42    
43       AutoServerThread(Socket s) 
44               throws IOException { 
45           oos = 
46                   new ObjectOutputStream( 
47                           s.getOutputStream()); 
48    
49           ois = 
50                   new ObjectInputStream( 
51                           s.getInputStream()); 
52       } 
53    
54       public void run() { 
55           try { 
56               Object o1 = ois.readObject(); 
57               Object o2 = ois.readObject(); 
58               if (o1 instanceof ByteCodeContainer) 
59                   ((ByteCodeContainer) o1).reload(); 
60               if (!(o2 instanceof ComputableObject)) { 
61                   System.out.println("Bad object!"); 
62                   return; 
63               } 
64               ComputableObject 
65                       co = (ComputableObject) o2; 
66               Object ans = co.compute(); 
67               oos.writeObject(ans); 
68               oos.close(); 
69               ois.close(); 
70           } catch (Exception e) { 
71               e.printStackTrace(); 
72           } 
73       } 
74    
75       public java.io.ObjectInputStream getOis() { 
76           return ois; 
77       } 
78    
79       public void setOis(java.io.ObjectInputStream ois) { 
80           this.ois = ois; 
81       } 
82    
83       public java.io.ObjectOutputStream getOos() { 
84           return oos; 
85       } 
86    
87       public void setOos(java.io.ObjectOutputStream oos) { 
88           this.oos = oos; 
89       } 
90   } 
91