• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Socket event when client disconnects?

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am familiar with socket programming in C but not so much in Java. In the sockets C interface there is a socket event received by the socket server when a client disconnects (does a shutdown or close). But I can't find the equivalent for Java.net.

How would I code this in Java? Do I get an exception of a certain type? Something else?

Angus
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your server will certainly get an exception if it tries to send data to a client which has already disconnected from the connection. I don't think the server gets notified until then, though. However it shouldn't be too hard to set up an experiment to find out for sure, should it?
 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Your server will certainly get an exception if it tries to send data to a client which has already disconnected from the connection. I don't think the server gets notified until then, though. However it shouldn't be too hard to set up an experiment to find out for sure, should it?



Looking on the web that was the impression I got, but wanted to check. Not getting such an event is a bit of a pain. I could set a timestamp for client activity and set a timer to periodically check if timestamp > a threshold and then send a short message to client to check - I guess that would work.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.io.EOFException will indicate the closing stream between sockets. This exception should help to identify the connection breakdown.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic