🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1381

Re: DataInputStream won't block

#1381
From: Alan Shiers
Date: Sun, 10 Feb 2002 19:34
66 lines
2901 bytes
Hi there,

Please disregard this last post.  I've since discovered a mistake in my
code.

Alan

Alan Shiers wrote:
> 
> Hi there,
> 
> I'm troubleshooting a client/server project.
> I'm using the DataInputStream object to read in integer values on the
> server-side app.  These integer values correspond with constants I have
> defined as being commands from the client-side app.
> 
> The code goes like this:
> 
> //this is created in the constuctor of the class
> DataInputStream input = new
> DataInputStream(connection.getInputStream());
> 
> //Since the class is threaded, in the run() method
> //I try to read in the Integer values
> 
> public void run()
> {
>    boolean done;
>    int incoming = 0;
>    while(!done)
>    {
>         incoming = input.readInt();  <<<here's the culprit
>         if(incoming == session.QUIT)
>         {
>            reset();
>            done = true;
>         }
>         else if(incoming == session.REQUEST_TREE)
>         {   System.out.println("Receiving request for Tree data");
>             //create the JTree object and
>             //send it out the wire
>             try
>             {
>               output.writeInt(session.SENDING_TREE_DATA);
>               sendFile(new File(homeDir));
>               output.flush();
>               System.out.println("completed sending tree data");
>             }
>             catch(IOException ioe){ioe.printStackTrace();}
> 
>         }
>         else if(yadda, yadda, yadda)
>         ...
>         ...
>    }
> }
> 
> At the top of the loop you can see that I'm trying to read in an Integer
> value.  However, for some reason, sometimes the method call to
> input.readInt() doesn't block and wait for and integer to come in over
> the wire. Instead, I wind up in an endless loop.  How come the method
> isn't blocking like it should every time.
> 
> Please advise,
> 
> Alan
Technical Details
Message-ID: <3C66CB29.C36F74EC@hfx.eastlink.ca>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!isdnet!feed.cgocable.net!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3C65955C.5566A0FC@hfx.eastlink.ca>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,ad9516f379110460
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-02-10 10:35:56 PST
Message-ID: <3C66CB29.C36F74EC@hfx.eastlink.ca>
Date: Sun, 10 Feb 2002 14:34:01 -0500
From: Alan Shiers <ashiers@hfx.eastlink.ca>
Organization: Mustard Seed Software
X-Mailer: Mozilla 4.78 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api
Subject: Re: DataInputStream won't block
References: <3C65955C.5566A0FC@hfx.eastlink.ca>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 24.222.101.2
X-Trace: dnews 1013366028 24.222.101.2 (10 Feb 2002 10:33:48 -0800)
Lines: 66
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!isdnet!feed.cgocable.net!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews