Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: Timeout Exceptions and the state of DataInputStream Date: Mon, 02 Apr 2012 14:14:05 -0700 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: <6b38110d-6a91-463c-ba4e-857a267705e8@b14g2000vbz.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 2 Apr 2012 21:14:06 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="6772"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sEgHDCC2SyU19aFEwU+p8" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 In-Reply-To: <6b38110d-6a91-463c-ba4e-857a267705e8@b14g2000vbz.googlegroups.com> Cancel-Lock: sha1:pqesFZ5sEgaPKxIwzF+95rICBeU= Xref: csiph.com comp.lang.java.programmer:13319 On 3/28/2012 4:59 PM, Ivan Ryan wrote: > I was wondering how the DataInputStream class handles Socket timeouts. > > For example, with code like the following: > > someSocket.setSoTimeout(1000); > > DataInputStream in = new DataInputStream(someSocket.getInputStream()); > > long x = in.readLong() > > What would happen if the stream times out when reading the long. > Would calling in.readLong() again give the correct value. This > assumes that the socket doesn't timeout the 2nd time. > > I assume that since the DataInputStream could be reading one byte at a > time, it doesn't hold internal state. This would mean that a few > bytes of the long could be lost? > > Another option is that the stream would "unread" the bytes or > something. I'm not sure why you would have a timeout of only 1 second but I would not expect the socket to timeout if you were actually reading data. Timeouts are typically designed to detect a lack of transmission of data for a given period. For a system with a remote connection I would think that 1 second could easily be too short a period. -- Knute Johnson