Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: detecting Socket disconnect Date: Thu, 18 Oct 2012 09:31:27 +0100 Organization: A noiseless patient Spider Lines: 16 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="e7be46fa422c8d3b64881aea51e84d96"; logging-data="4969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PMg0zABB/Pu8CdKJsyxNansp/2UaVKpQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 In-Reply-To: Cancel-Lock: sha1:bD6B0z7bmtA3lb7CVIiY258SCAo= Xref: csiph.com comp.lang.java.programmer:19430 On 17/10/12 21:59, Peter Duniho wrote: > On Wed, 17 Oct 2012 13:12:13 -0700 (PDT), bob smith wrote: >> I have a java.net.Socket that I only write to, and I can't figure out how to tell if it's disconnected. > The normal way to detect a disconnect is to read from the socket and get a > return value of 0 bytes for the count of bytes. This is the case in C, where functions like recv() use -1 to signal an error and 0 for EOF. However, in Java, InputStream (such as you get from a Socket) returns -1 to signal EOF. -- ss at comp dot lancs dot ac dot uk