This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Please help with BufferReader.read() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Please help with BufferReader.read()" Watch "Please help with BufferReader.read()" New topic
Author

Please help with BufferReader.read()

V Johnson
Greenhorn

Joined: Jul 28, 2003
Posts: 1
The problem is that my application is hanging on the br.read()line!! Please help me...

Code Tags added by M^2
[ July 28, 2003: Message edited by: Michael Morris ]
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
well, if your program is *hanging* with the buffered reader, then I guess the read() is blocking.
There seems to be nothing on the network i/p buffer and hence the read() blocks, waiting for something to arrive.
It would be great if you can post the client code too.
In the meantime, I will look around the problem with a client of my own.
Cheers
Lupo


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
Nick Revak
Greenhorn

Joined: Jun 08, 2003
Posts: 4
The third parameter in the read is the maximum characters to attempt to read.
You could simply try setting your array size to a value much bigger than your would ever expect for contentLength.
But I also think you'd want to do your reads within a while loop (checking for end of stream). If you do this, you need to manage the size of each read to ensure you don't exceed your array.
Try this ....
int currentArrayPos = 0;
int count = 0;
//then, change the max char parameter in your read ....
while ((count = br.read(buf, 0, contentLength - currentArrayPos) != -1 ) {; //***HERE'S THE PROBLEM!!
// and limit the size of each read
currentArrayPos = currentArrayPos + count
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help with BufferReader.read()
 
Similar Threads
File Transfer via Sockets
How to append response to the incoming request from Socket and write to another Socket.....
Java Server limit
Java net BindException:Address already in use: JVM_Bind
FTP(File transfer)