Article View: borland.public.jbuilder.java.api
Article #1294Re: Dead Socket doesn't throw exception
From: Owen Green
Date: Mon, 01 Apr 2002 15:57
Date: Mon, 01 Apr 2002 15:57
37 lines
2491 bytes
2491 bytes
Joi Ellis [TeamB] <joi@aravox.com> wrote in message news:3ca86f83_1@dnews... > Owen Green <owen@begonefoulmachine.kennulz.demon.co.uk> wrote: > > Hi, > > > I'm having a bit of trouble reliably detecting when a socket has been > > disconnected from the other end. I've seen various opinions around the place > > that a read or write should result in an exception when this has happened, > > but the code below fails to produce one (at least on my system which is, > > gack, w95). > > As I understand it, when a remote socket shuts down normally, your IO streams > will see EOF markers, not exceptions. You'll get an exception if the > socket dies without being properly closed, IE the remote program crashed > and didn't clean up, the host crashed, or some device tossing packets between > the two hosts has stopped cooperating. That's when you get a socket > exception. That makes sense. > Don't you have to read once before you can get an EOF indication? It appears not. > What happens if you alter the test as follows? (Look for //### comments.) It doesn't compile (println not being a method of OutputStream) <g> It behaves as expected (i.e. reads those bytes out and then returns -1s). I suppose I could use some sort of latch so EOFs will only have attention paid to them after the first successful read, but it's a bit hacky. If the far end is suppossed to send a TCP FIN or somesuch when it closes gracefully it seems a bit silly that one can't reliably detect it. Cheers for your help, Owen
Technical Details
Message-ID:
<3ca881fe$1_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.online.be!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3ca7b409_1@dnews> <3ca86f83_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,a31ecd0db1134a2e X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-04-01 07:55:56 PST From: "Owen Green" <owen@begonefoulmachine.kennulz.demon.co.uk> Newsgroups: borland.public.jbuilder.java.api References: <3ca7b409_1@dnews> <3ca86f83_1@dnews> Subject: Re: Dead Socket doesn't throw exception Date: Mon, 1 Apr 2002 16:57:01 +0100 Lines: 42 Organization: Unique Interactive X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: 217.134.97.99 Message-ID: <3ca881fe$1_2@dnews> X-Trace: dnews 1017676286 217.134.97.99 (1 Apr 2002 07:51:26 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!newsfeed.online.be!news-hog.berkeley.edu!ucberkeley!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews