Java socket polling for checking if client is available -


i trying poll socket on server side check if client still available. checked few threads here nothing seems work.

as found out there no direct way of checking tried perform write opperation socket and... java writing socket (when client disconnected) , no exception ioexception expected.

i set thread supposed perform polling sending packet each second. while sending disconnected client after minute response "operation timed out".

i tried mess around socket setsotimeout doens't work expected either.

anyone has suggestions how make work?

thank in advance.

best regards, tom

why not receive call , catch exceptions. if broken pipe exception or socket timeout, know client no longer present.

for such cases, typical approach server set tcp keepalive using setkeepalive , getkeepalive methods. http://docs.oracle.com/javase/6/docs/api/java/net/socket.html . if client goes away, tcp keepalive kick in (becuase of inactivity) , detect client disconnected. then, close connection. subsequent recv() call return value of -1 , error indicating same.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -