bcz
February 16th, 2011, 01:35 AM
Hi all
My applet connects to a local server. If not found, it loads the server and retries the connection.
"java class" runs fine, but running in a browser using html fails to load server. html works fine if server is already running.
I am using the Runtime class to start the server. Dont know if there is a recommended way of doing this
My client code and html is attached
Snippet to start server
SocketAddress sa;
while(starting){
try{ link= new Socket("localhost",PORT);
ta.append("Server connect on port "+PORT+"\n");
starting=false;
}catch (Exception e){
ta.append("Server not found\n");
ta.append("Error: "+e+"\n");
cnt++; if(cnt==3)return;
try{ ta.append("Starting Server\n");
Runtime rt=Runtime.getRuntime();
Process proc=rt.exec("java Misam");
try{ Thread.sleep(1000);
}catch (InterruptedException ie){ta.append(ie.getMessage()+"\n");}
}catch (Throwable t){ ta.append("Server started\n");}
}
My applet connects to a local server. If not found, it loads the server and retries the connection.
"java class" runs fine, but running in a browser using html fails to load server. html works fine if server is already running.
I am using the Runtime class to start the server. Dont know if there is a recommended way of doing this
My client code and html is attached
Snippet to start server
SocketAddress sa;
while(starting){
try{ link= new Socket("localhost",PORT);
ta.append("Server connect on port "+PORT+"\n");
starting=false;
}catch (Exception e){
ta.append("Server not found\n");
ta.append("Error: "+e+"\n");
cnt++; if(cnt==3)return;
try{ ta.append("Starting Server\n");
Runtime rt=Runtime.getRuntime();
Process proc=rt.exec("java Misam");
try{ Thread.sleep(1000);
}catch (InterruptedException ie){ta.append(ie.getMessage()+"\n");}
}catch (Throwable t){ ta.append("Server started\n");}
}