java - About checking whether a client is disconnected from the Server Socket -


this question has answer here:

from (java network programming fourth edition): tell if socket open, need check isconnected() returns true , isclosed() returns false. example:

boolean connected = socket.isconnected() && ! socket.isclosed(); 

i need find way discover possible client has disconnected server socket. using trick described above,i have tried following :

    socket socket = ...;     while (socket.isconnected() && !socket.isclosed()) {       // ...       // here, client connected         }     // client disconnected  

the above approach works me, correct?. detects cases?

depending on application, catching exceptions intelligently seem solution. requirement, however, wants send/do client. possibly combination of 2 approaches suits specific application. try seeing: java detect lost connection


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -