more xwt -> ibex cleanup
[nestedvm.git] / src / tests / Echo.java
1 package tests;
2
3 import java.net.*;
4
5 import org.ibex.nestedvm.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 = (Runtime) Class.forName("tests.EchoHelper").newInstance();
22                 task.closeFD(0);
23                 task.closeFD(1);
24                 task.closeFD(2);
25                 task.addFD(new Runtime.InputStreamFD(sock.getInputStream()));
26                 task.addFD(new Runtime.OutputStreamFD(sock.getOutputStream()));
27                 task.dupFD(1);
28                 
29                 int status = task.run(new String[]{"EchoHelper"} );
30                 System.err.println("Exit status: " + status);
31             } catch(Exception e) {
32                 System.err.println(e);
33             }
34         }
35     }
36 }