Kevin Brooks

Greenhorn
+ Follow
since Jan 18, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kevin Brooks

I am trying to add components to a JPanel. Everything works great until I want to drop down and create another row of components. I have tried using the setAlignmentY() method, however it does not move down at all. Maybe I am not adding a large enough value to the previous value used. I am adding 250 for each "row" I want to create. Is there another method I should be using?
13 years ago

Paul Clapham wrote:Well, the code you posted won't do that anyway, it will just block when it has to wait for data to arrive from the network partner.

<Kevin> Am I wrong in thinking the "if(super.ready())" will prevent my code from attempting to read a character if there is none?

However if your requirement is for the connection to time out if no data is received within a certain period, it would be better to just set that timeout on the socket, rather than trying to hack the system at a completely different level. Then you just write ordinary text-reading code which is prepared for IOExceptions to be thrown when the timeouts occur.

<Kevin> This may work. However, wouldn't the Socket shut down if there is a timeout? If so this would not be a good solution since I have to send the device a command after I finish even if I did not get all the data I was expecting. Also the other Device sends Keep Alive packets to me so wouldn't this prevent the timeout at the Socket level?

Also, if you don't want your application to be hung up by code waiting for input, it's usual in networking applications to run that code in a separate thread.

<Kevin>
I am already running it in a separate thread, so I mislead you a bit. The whole application won't hang up, but that thread would if Data doesn't come across.

13 years ago
I have Extended the Buffered Reader class. The purpose was to create a Readline method that will time out. The reason for this is I using Buffered reader to communicate with a device over the network, if the device does not respond I do not want my program to be hung up. Any way below is the code for my method. Is there a better way to check for the time out period? Or maybe there is already a class and/or method that does what I am looking for?

Thanks,
Kevin

/***********************************************
* This function is called to read a line of text from
* a buffered reader. It will read until a Carriage Return and/or
* line feed is read, or until the time limit has expired.
* @param tlimit The amount of time in milliseconds to wait for a end of line
* character.
* @param value This variable will be filled with the characters collected during
* the reading process. It will not contain the end of line character(s)
* @return The return value is boolean indicating if a end of line character was read.
*/
public boolean readLine(int tlimit, StringBuffer value) throws IOException
{
boolean retval = false;

if(lastCharRead != 0 && lastCharRead != 13 && lastCharRead != 10){
value.append(lastCharRead);
}

lastCharRead = 0;
Date finish = new Date();

finish.setTime(finish.getTime() + (tlimit / 10));
Date current = new Date();

while(current.before(finish) && !retval){
if(super.ready()){
char cread = (char) super.read();
if(cread != 10 && cread != 13){
value.append(cread);
}
else{
retval = true;
if(cread == 13 && super.ready()){
lastCharRead = (char) super.read();
lastCharRead = (lastCharRead == 10 ? 0 : lastCharRead);
}
}
}

current = new Date();

}

return retval;
}
13 years ago
If I could access the Args from the Startup() method, that would work.
13 years ago
I have a program I started with Netbeans and let it generate the initial program for me. Now I need my Frameview object to have access to the command line arguments? Is there a simple way to either retrieve them from my Frameview object, or pass them into my Frameview object?
13 years ago