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