• Post Reply Bookmark Topic Watch Topic
  • New Topic

How Do You Determine a Closed Socket?  RSS feed

 
Matt Midcap
Sheriff
Posts: 440
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a socket connection from my client to a server. I am trying all kinds of things to determine if the server goes down. Hence the socket is closed, right?
Does anyone know how to determine that the connection from the server has been closed? No - the server does not send keep alives.
Thanks,
Matt
 
paul wheaton
Trailboss
Posts: 22577
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't an exception be thrown? Try opening a connection and then physically pulling the plug.
 
Matt Midcap
Sheriff
Posts: 440
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One would think so, but no, not to be. You would also think that Sun would have known about this problem for a long time now and prehaps made a method like "isOpen()". But no.
I have been researching this extensively and it looks like there are a bunch of "hacks" to try and get around this problem.
Does anyone out there have a good hack that isn't too bad to use?
Thanks,
Matt
 
Matt Midcap
Sheriff
Posts: 440
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I did my own hack and it works. Unfortunatly this was the straw that broke the camels back for the project I'm working on.
I had to sell my boss (a non-Java, OOP guy) on using Java. I did for the most part. Unfortunatly there have been so many "wierd" and down right screwed-up issues with using Java (see the Paul's thread about applets, this issue, and JRE version issues) that another developer in my group want to use C++ now.
And of course my boss thinks he is right and after the next version of my application in Java comes out we are going to start working on the C++ version and drop Java.
What a shame! Shame, shame, shame... I hope the issues that killed our project are remediated by Sun soon. This issue (not being able to detect a socket drop easily) is a major one that needs to be fixed with no more excusses.
MM
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an interesting article JDC site on
"Simple Handling of Network Timeouts"
http://developer.java.sun.com/developer/technicalArticles/Networking/timeouts/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!