E
ed doyle
Hi,
I am relatively new to Java programming, but I have created a simple
server application and a client applet largely from following the
examples in Deitel's "Java - How to Program Book".Everything works
perfectly if I start the server application, and then run the client
applet in appletviewer. But I thought I would get fancy and add code to
the client that if the server application was not running, the client
would gracefully shut down. Here is my first attempt which does not work.
public void start() {
while(connection == null) {
try {
connection = new Socket(InetAddress.getLocalHost(),
5000);
input = new
DataInputStream(connection.getInputStream());
output = new
DataOutputStream(connection.getOutputStream());
}
catch(IOException e) {
//e.printStackTrace();
System.out.println("Unable to connect to server!");
System.exit(0);
}
}
outputThread = new Thread(this);
outputThread.start();
}
When I run the client with no server, I get the following stack trace.
Unable to connect to server!
java.security.AccessControlException: access denied
(java.lang.RuntimePermission exitVM)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at
java.security.AccessController.checkPermission(AccessController.java:401)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkExit(SecurityManager.java:736)
at java.lang.Runtime.exit(Runtime.java:88)
at java.lang.System.exit(System.java:715)
at TicTacToeClient.start(TicTacToeClient.java:64)
at sun.applet.AppletPanel.run(AppletPanel.java:377)
at java.lang.Thread.run(Thread.java:534)
Line 64 is where I added the line System.exit(0); I'm not sure what the
stack trace is telling me or where to look for the problem. I have
seen other code where a System.exit(0); line is placed in a catch
clause, so I 'think' that is valid. I am not sure if there is a problem
with putting it in a start() method, or if the issue is I am off in a
thread telling the entire applet to shut down. Any clues on what I
should read next, or what I need to next learn to cope with this problem
would be useful. I don't need the problem solved for me, just a pointer
on where to look next.
Thanks for any comments.
Ed
I am relatively new to Java programming, but I have created a simple
server application and a client applet largely from following the
examples in Deitel's "Java - How to Program Book".Everything works
perfectly if I start the server application, and then run the client
applet in appletviewer. But I thought I would get fancy and add code to
the client that if the server application was not running, the client
would gracefully shut down. Here is my first attempt which does not work.
public void start() {
while(connection == null) {
try {
connection = new Socket(InetAddress.getLocalHost(),
5000);
input = new
DataInputStream(connection.getInputStream());
output = new
DataOutputStream(connection.getOutputStream());
}
catch(IOException e) {
//e.printStackTrace();
System.out.println("Unable to connect to server!");
System.exit(0);
}
}
outputThread = new Thread(this);
outputThread.start();
}
When I run the client with no server, I get the following stack trace.
Unable to connect to server!
java.security.AccessControlException: access denied
(java.lang.RuntimePermission exitVM)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at
java.security.AccessController.checkPermission(AccessController.java:401)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkExit(SecurityManager.java:736)
at java.lang.Runtime.exit(Runtime.java:88)
at java.lang.System.exit(System.java:715)
at TicTacToeClient.start(TicTacToeClient.java:64)
at sun.applet.AppletPanel.run(AppletPanel.java:377)
at java.lang.Thread.run(Thread.java:534)
Line 64 is where I added the line System.exit(0); I'm not sure what the
stack trace is telling me or where to look for the problem. I have
seen other code where a System.exit(0); line is placed in a catch
clause, so I 'think' that is valid. I am not sure if there is a problem
with putting it in a start() method, or if the issue is I am off in a
thread telling the entire applet to shut down. Any clues on what I
should read next, or what I need to next learn to cope with this problem
would be useful. I don't need the problem solved for me, just a pointer
on where to look next.
Thanks for any comments.
Ed