how can I know client disconnected?

hi,

I am trying to create a Client-Server application.

on the server side I have this code .

publicvoid run()

{

ServerSocket server =null;

Socket socket =null;

//store client information and pass to the event object

Hashtable<String, String> ClientInfo =new Hashtable<String, String>();

try{

try{

server =new ServerSocket(getPort());

}catch(IOException e){

this.exceptionThrown(e);

}

//listen for connections

while (true)

{

try{

socket = server.accept();

ClientInfo.put("remoteip", socket.getInetAddress().toString());

fireServerEvent(new ServerEvent(ClientInfo, ServerEvent.CONNECTION_REQUESTED,null));

ThreadedSocket handler = getThreadedSocket(socket);

Sockets.add(handler);

handler.start();

fireServerEvent(new ServerEvent(ClientInfo, ServerEvent.CONNECTION_ESTABLISHED,null));

}catch (IOException ioe){

exceptionThrown(ioe);

}

}

}catch(Exception x){

exceptionThrown(x);

}finally{

try{

server.close();

socket.close();

}catch (Exception e){

exceptionThrown(e);

}

}

}

and I would like to ask if there is any way for me to know that a client disconnected (client-side::socket.close()) in order to fire aclientDisconnected event.

Message was edited by:

xpanta

[2805 byte] By [xpantaa] at [2007-11-27 0:15:24]
# 1
What is the server doing at the time? If it is waiting on a blocking read(), then -1 will be prematurely returned. If i t is outputting via write(), you will get an IOException. - Saish
Saisha at 2007-7-11 22:02:11 > top of Java-index,Java Essentials,Java Programming...
# 2

Just an observation, but the server really shouldn't know or care about the client(s) connected to it. It should be serving up in formation and if (and only if) anybody is interested in getting it they should be pulling it. More accurately it shouldn't serve anything up unless or until someone has asked for it, but that's not always a hard rule.

Nutshell version of my point, you're doing it backwards.

PS.

puckstopper31a at 2007-7-11 22:02:11 > top of Java-index,Java Essentials,Java Programming...