java - Dispatching an event for a closed socket -


i'm doing event disconnect client. here code:

public void run(){     while(isconnected()){         system.out.println("asd");               }     serverlistener.clientdisconnect(clientid); }  public boolean isconnected(){     if(socket.isclosed() || !socket.isconnected() || socket.isinputshutdown() || socket.isoutputshutdown()){         return false;     }     return true; } 

the problem have results:
isclosed = false
isconnected = true
isinputshutdown = false
isoutputshutdown = false

and when client disconnects, have same result: nothing happens.

that correct. flags tell did.

you haven't closed connection, connected once, haven't shutdown input or output.

the way know if connection closed when fail read socket. (or selector notifies you)

note: because other end has closed connection, doesn't mean want close. imagine have http request , server sends response , closes connection. want connection close if haven't read data, @ random point, possibly before have finish or started? don't, want know closed once have read data.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -