Hi,
My code looks like this, this is Server code (Runnable
)
public void run() {
while (true) {
try {
System.out.println("Waiting for client...");
this.socket = serverSocket.accept();
System.out.println("Client accepted");
while (true) {
readCommand();
try {
Thread.sleep(2);
} catch (Exception e) {
}
}
} catch (Exception ex) {
Main.error("Server stopped for current host", ex);
}
}
}
My problem is: when the client closes the connection, he still waiting to read the command in readCommand();
until a command was sent and an EOFException
will be thrown. This is my readCommand
method:
private void readCommand() throws Exception {
Object o = new ObjectInputStream(socket.getInputStream()).readObject();
if (o instanceof Command) {
((Command) o).execute();
return;
}
if (o instanceof Recorder) {
System.out.println("Recording received");
((Recorder) o).executeRecord();
return;
}
if (o instanceof MyKeyEvent) {
((MyKeyEvent) o).execute();
return;
}
}
So I think before reading he have to check if the connection is open. I hope I've explained well. Maybe bad English (14 years old, Dutch speaking).
Edit: If I evaluate the run
-method code, the EOFException
is trown in the try-catch-body
. But he stops accepting clients.
Thanks