Solved

Socket Exceptions

Posted on 2004-08-25
7
188 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat not starting 6 68
JAVA API design with micro service cloud in mind 1 47
Is there a simpler dropbox system? 10 34
java example issue 3 23
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

860 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