Solved

Socket Exceptions

Posted on 2004-08-25
7
171 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
java continue statement 10 72
count7 challenge 12 67
array220 challenge 8 45
Eclipse IDE - Cannot copy/paste from console output 8 58
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now