* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / tests / network / DemoServer.java
1 import java.net.*;
2 import java.io.*;
3
4 public class DemoServer extends Thread
5 {
6         ServerSocket listenSock;
7
8         public static void main(String[] args)
9         {
10                 DemoServer app = new DemoServer();
11                 app.start();
12         }
13
14         public DemoServer()
15         {
16         }
17
18         public void run()
19         {
20                 Socket newSocket;
21
22                 try {
23                         listenSock = new ServerSocket(5758);
24                         System.out.println(listenSock.toString());
25                 } catch (Exception hell) {
26                         System.out.println("Error setting up listen socket:\n");
27                         System.out.println(hell);
28                         return;
29                 }
30
31                 while (true)
32                 {
33                         try {
34                                 System.out.println("Trying accept");
35                                 newSocket = listenSock.accept();
36                                 System.out.println("Accept returned");
37                         } catch (Exception badAccept) {
38                                 continue;
39                         }
40                         System.out.println("Accepted new client");
41
42                         try {
43                                 DataInputStream inStream = new DataInputStream(
44                                         newSocket.getInputStream());
45                                 System.out.println("Client send "+inStream.readInt());
46                                 newSocket.close();
47                         } catch (Exception oops) {
48                                 System.out.println("Error reading from client");
49                                 System.out.println(oops);
50                         }
51                 }
52         }
53 }