Solved

Socket Exceptions

Posted on 2004-08-25
7
201 Views
Last Modified: 2010-03-31
Is it possible to have exception from an InputStream.read or an OutputStream.write using java.lang.Socket and the socket still be valid (readable/writable)?  What I am getting at is if an exception occurs during a socket read/write should I automatically consider the socket connection invalid?  Is there any documentation on this?

Thanks
0
Comment
Question by:nealgoodman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11894709
No, it doesn't necessarily make the Socket invalid, though it depends on why it was caused. What are the specifics?
0
 
LVL 1

Author Comment

by:nealgoodman
ID: 11896873
I guess what I want is a checklist of items that cause a socket to become invalid.  I want to make sure that I am able to determine when the socket is no longer valid.  I know the only real way to do this is to get a write failure.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11896924
>>I know the only real way to do this is to get a write failure.

That's quite right, and probably the only real way to tell with accuracy
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 92

Expert Comment

by:objects
ID: 11898047
You should consider the socket invalid after you have recieved an exception.
Unless you have a specific reason to believe otherwise.
0
 
LVL 1

Author Comment

by:nealgoodman
ID: 11899168
>You should consider the socket invalid after you have recieved an exception.
>Unless you have a specific reason to believe otherwise.

Is there any documentation on this?  What would be a good "specific reason"? Currently I am doing exactly what you are saying in conjunction with a "ping" message we send every N seconds to make sure the socket is still alive.
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 11899230
> What would be a good "specific reason"?

If you are not aware of any then there probably aren't any :)
There's an unlimited number of different type of exceptions that could occur, so getting a definitive answer is probably not even possible.
When in doubt your safest assuming the connection is trashed, otherwise you could end up in an even bigger mess. And when you find any exceptions that don't trash it, then add special handling for that exception.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11901475
Hmm. Not quite sure why you accepted that as the only 'correct' answer. Perhaps you can illuminate ...?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question