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