38 {
39 try{
40
41 final String VERSION = "1.00" ;
42 final String DATE = "August 19, 1997";
43
44 final int PORT_NO = 40801 ;
45 final String OUTPUT_FILE_HEAD = "g4" ;
46 final String OUTPUT_FILE_EXT = "wrl" ;
47 final int MAX_TRIAL = 10 ;
48
49
50 int portNo = PORT_NO ;
51
52
53 if( args.length != 1 && args.length != 2 )
54 {
55 System.out.println( "-------------------------------");
56 System.out.println( " G4VRMLView version " + VERSION );
57 System.out.println( " " + DATE );
58 System.out.println( "-------------------------------");
59 System.out.println( "Usage: java g4vrmlview browser_name [port_number]");
60 System.out.println( " Browser_name: netscape, vrweb, etc, or NONE");
61 return ;
62 }
63
64
65 String browser = new String ( args[0] ) ;
66
67
68 if( args.length == 2 )
69 {
70 portNo = Integer.parseInt( args[1] );
71 }
72
73
74 ServerSocket ss = null ;
75 for ( int i = 0 ; i < MAX_TRIAL ; i++ )
76 {
77 try
78 {
79 ss = new ServerSocket( portNo );
80 System.out.println( "Waiting for requests at port " +portNo + " ...");
81 break ;
82 }
83 catch ( Exception e )
84 {
85 portNo++ ;
86 if( i >= MAX_TRIAL )
87 {
88 System.out.println( "Sockets are not available.");
89 return ;
90 }
91 }
92 }
93
94
95
96 int nSpawn = 0 ;
97 while( true )
98 {
99 Socket socket = ss.accept(); nSpawn++ ;
100
101 System.out.println( "Connection accepted by thread " + nSpawn );
102
103 ( new g4vrmlviewThread( socket, OUTPUT_FILE_HEAD, OUTPUT_FILE_EXT , browser )).start() ;
104
105 }
106
107 }
108 catch ( Exception e )
109 {
110 System.out.println( e.toString() );
111 }
112 }