47f8046f245f840ed70ed9a4e946885cc50abda6
[nestedvm.git] / src / tests / Echo.java
1 package tests;
2
3 import java.net.*;
4
5 import org.xwt.mips.Runtime;
6
7 public class Echo {
8     private static final int PORT = 2000;
9     public static void main(String[] args) throws Exception {
10         ServerSocket sock = new ServerSocket(PORT);
11         System.err.println("Listening on " + PORT);
12         for(;;) new Client(sock.accept()).go();
13     }
14     
15     private static class Client implements Runnable {
16         private Socket sock;
17         public Client(Socket sock) { this.sock = sock; }
18         public void go() { new Thread(this).start(); }
19         public void run() {
20             try {
21                 Runtime task = new EchoHelper();
22                 int status = task.run(
23                     new String[]{"EchoHelper"},
24                     null,
25                     new Runtime.InputStreamFD(sock.getInputStream()),
26                     new Runtime.OutputStreamFD(sock.getOutputStream()),
27                     null
28                 );
29                 System.err.println("Exit status: " + status);
30             } catch(Exception e) {
31                 System.err.println(e);
32             }
33         }
34     }
35 }