38 public static void main( String[] args )
42 final String VERSION =
"1.00" ;
43 final String DATE =
"August 19, 1997";
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 ;
51 int portNo = PORT_NO ;
54 if( args.length != 1 && args.length != 2 )
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");
66 String browser =
new String ( args[0] ) ;
69 if( args.length == 2 )
71 portNo = Integer.parseInt( args[1] );
75 ServerSocket ss = null ;
76 for (
int i = 0 ; i < MAX_TRIAL ; i++ )
80 ss =
new ServerSocket( portNo );
81 System.out.println(
"Waiting for requests at port " +portNo +
" ...");
89 System.out.println(
"Sockets are not available.");
100 Socket socket = ss.accept(); nSpawn++ ;
102 System.out.println(
"Connection accepted by thread " + nSpawn );
104 (
new g4vrmlviewThread( socket, OUTPUT_FILE_HEAD, OUTPUT_FILE_EXT , browser )).start() ;
109 catch ( Exception e )
111 System.out.println( e.toString() );
121 class g4vrmlviewThread
extends Thread
123 private final String
NONE =
"NONE" ;
124 private Socket m_socket ;
125 private String m_outputFile ;
126 private String m_browser ;
129 public g4vrmlviewThread( Socket socket ,
130 String outputFileHead ,
131 String outputFileExt ,
135 SetOutputFileName ( outputFileHead , outputFileExt );
136 m_browser =
new String ( browser );
139 private void SetOutputFileName( String outputFileHead,
140 String outputFileExt )
143 String outputFile_tmp
144 =
new String ( outputFileHead +
154 File file =
new File ( outputFile_tmp );
156 if ( !file.exists() )
162 =
new String ( outputFileHead +
172 m_outputFile =
new String ( outputFile_tmp );
183 =
new BufferedReader (
new InputStreamReader ( m_socket.getInputStream() ) ) ;
187 =
new BufferedWriter (
new FileWriter ( m_outputFile ) ) ;
191 while ( (line = br.readLine()) != null )
197 System.out.println(
"VRML data is saved to file " +m_outputFile );
205 if( !m_browser.equals(
NONE) )
210 File file =
new File ( m_outputFile );
215 String outputFileAbs =
new String ( file.getAbsolutePath() ) ;
216 String[] command = { m_browser, outputFileAbs };
217 System.out.println(
"Command: " + command[0] +
" " + command[1] );
219 Process exec_process = null ;
221 Runtime runtime = Runtime.getRuntime();
222 exec_process = runtime.exec( command );
223 exec_process.waitFor() ;
225 System.out.println(
"Error: Failed to open file" + m_outputFile );
228 catch ( Exception e )
230 System.out.println( e.toString() );
236 System.out.println(
"No browser was invoked" );
242 System.out.println( e.toString() );
static void main(String[] args)