How to know which socket is desconnected?

I have the next code. When one of the clients is desconnected, all the other clients recieve the message "null" all the time and not the message : user+" desconnected..."

public TareaServidor(Socket param1, ArrayList param2)

{

client = param1;

clients = param2;

try

{

br = new BufferedReader(new InputStreamReader(client.getInputStream()));

bw = new PrintWriter(client.getOutputStream(), true);

}

catch(IOException ex)

{

sw = false;

ex.printStackTrace();

}

}

public void run()

{

try

{

String tmp = this.recieve();

user = tmp.substring(tmp.indexOf(": ") + 2, tmp.length());

this.broadcast("## User " + user + " connected....");

while(sw)

{

this.broadcast(this.recieve());

}

}

catch(SocketException ex)

{

try

{

this.broadcast(user+" desconnected...");

}

catch(IOException ex2)

{

ex2.printStackTrace();

}

}

catch(IOException ex2)

{

ex2.printStackTrace();

}

finally

{

try

{

if(br != null)

br.close();

}

catch(IOException ex)

{

ex.printStackTrace();

}

if(bw != null)

bw.close();

try

{

if(client != null)

client.close();

}

catch(IOException ex)

{

ex.printStackTrace();

}

}

clients.remove(this);

}

private void broadcast(String param) throws IOException

{

for(int i = 0; i < clients.size(); i++)

if(clients.get(i) != this)

((TareaServidor)clients.get(i)).send(param);

}

private void send(String param) throws IOException

{

bw.println(param);

bw.flush();

}

private String recieve() throws IOException

{

return br.readLine();

}

}

[1928 byte] By [berlinerwurma] at [2007-11-27 4:34:39]
# 1
The socket that gets a null return from br.readLine is the one that has been disconnected. When you get that you must close the socket concerned and not propagate the null, which isn't data.
ejpa at 2007-7-12 9:44:36 > top of Java-index,Core,Core APIs...