Article View: borland.public.jbuilder.java.api
Article #1380DataInputStream won't block
From: Alan Shiers
Date: Sat, 09 Feb 2002 21:32
Date: Sat, 09 Feb 2002 21:32
57 lines
2684 bytes
2684 bytes
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:
<3C65955C.5566A0FC@hfx.eastlink.ca>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!isdnet!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!hub1.nntpserver.com!news-out.spamkiller.net!propagator-la!news-in-la.newsfeeds.com!news-in.superfeed.net!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,ad9516f379110460,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-02-09 12:32:50 PST Message-ID: <3C65955C.5566A0FC@hfx.eastlink.ca> Date: Sat, 09 Feb 2002 16:32:12 -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: DataInputStream won't block Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.222.101.2 X-Trace: dnews 1013286722 24.222.101.2 (9 Feb 2002 12:32:02 -0800) Lines: 57 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!isdnet!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!hub1.nntpserver.com!news-out.spamkiller.net!propagator-la!news-in-la.newsfeeds.com!news-in.superfeed.net!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews