0

How can I find when a connection is closed?

I have developed an application which allows you to send messages to a "group chat", however there is an error when one of the connections closes, obviously.

I want to know how to handle this error, for example, remove the PrintWriter from the ArrayList of the person who closed their connection.

How do I do this?

        public void run()
    {
        String message;
        try {
            while ((message = reader.readLine()) != null) {
                send(message);
            }
        } catch (Exception e) {

        }
    }
Archie K
  • 15
  • 1
  • 5
  • By checking if the connection is open / by catching the exception /... this is too broad like this. What type of `Connection`. – AxelH Dec 16 '16 at 14:34
  • I'm using PrintWriter and BufferedReader. – Archie K Dec 16 '16 at 14:35
  • In this example. What is wrong ? You will end up in the catch part and that's it, manage that and that would be enough. Not sure what is the problem. – AxelH Dec 16 '16 at 14:41
  • Check this if this helps : http://stackoverflow.com/a/25940409/1085186 – StackFlowed Dec 16 '16 at 14:41
  • Possible duplicate of [How to check whether an OutputStream is closed](http://stackoverflow.com/questions/8655901/how-to-check-whether-an-outputstream-is-closed) – AxelH Dec 16 '16 at 14:42
  • I think I maybe need to remove the client from the server, just about to look at those links, thank you SF and Axel. – Archie K Dec 18 '16 at 09:46

0 Answers0