Solved

Socket Exceptions

Posted on 2004-08-25
7
193 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 63
Bot application - advice 3 63
collection output issue 9 66
How to log java errors in tomcat 8 24
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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