Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: rcs/nml/autoconf.java


1   /*
2    * File: autoconf.java 
3    */
4   
5   package rcs.nml;
6   
7   
8   import java.util.*;
9   import java.io.*;
10  import java.net.*;
11  import rcs.*;
12  import rcs.utils.*;
13  import rcs.nml.*;
14  
15  
16  /*
17  
18  class quit_waiter implements Runnable
19  {
20    
21    DataInputStream dis = null;
22    Thread quit_waiter_thread = null;
23  
24    public void start()
25    {
26      quit_waiter_thread = new Thread(this);
27      quit_waiter_thread.start();
28    }
29  
30    public void run()
31    {
32      dis = new DataInputStream(System.in);
33      while(true)
34        {
35    try
36      {
37        Thread.sleep(1000);
38        String input_string = dis.readLine();
39        if(input_string.toLowerCase().startsWith("q"))
40          {
41      autoconf.killme = true;
42      if(null != autoconf.connect_socket)
43        {
44          autoconf.connect_socket.close();
45        }
46      if(null != autoconf.mainThread)
47        {
48          autoconf.mainThread.interrupt();
49        }
50      break;
51          }
52      }
53    catch(Exception e)
54      {
55        e.printStackTrace();
56      }
57        }
58    }
59  }
60  */
61  public class autoconf
62  {
63  
64    public static autoconfDB db;
65    
66    public static int port = 11671;
67    public static boolean killme = false;
68    public static Vector threadList = new Vector();
69    public static ServerSocket connect_socket = null;
70  
71    static public void main(String args[])
72    {
73      try
74        {
75    for(int i=0; i < args.length; i++)
76      {
77        if(args[i].toLowerCase().startsWith("port="))
78          {
79      try
80        {
81          port = Integer.valueOf(args[i].substring(5)).intValue();
82        }
83      catch(Exception e)
84        {
85          e.printStackTrace();
86        }
87          }
88      }
89    
90    connect_socket = new ServerSocket(port);
91    InetAddress ia = InetAddress.getLocalHost();
92    System.out.println("NML Automatic Configuration server running on "+ia+" on port "+port+".");
93    try
94      {
95        while(!killme)
96          {
97      Socket client_socket = connect_socket.accept();
98      autoconfThread  acThr = new autoconfThread(client_socket);
99      threadList.addElement(acThr);
100     acThr.start();
101         }
102     }
103   catch(Exception e)
104     {
105       if(!killme)
106         {
107     e.printStackTrace();
108         }
109     }
110   connect_socket.close();
111   System.out.println("autoconf exiting.");
112   System.exit(0);
113       }
114     catch(Exception e)
115       {
116   e.printStackTrace();
117       }
118     
119   }
120 
121 }