Hello all,

I'm developing the java applet to received the numerical data from socket and then plot it with jfreechart. I used java thread to poll the socket via readline. This java applet contains in the Embedded Web server of Wiport (The Serial to WiFi Module). I've a problem of
1. Delayed of reading the data from socket which
when I turned the Wiport off (No power supplied). The applet still plot the graph if the data come so many.My data arrival rate to the applet is 57600 bps. My thread read period is thread.sleep(0,(int)read_period); (read_period = 50)
2. Are there any method to improve the speed of read the data ? or Any suggestion of my method?
3. Can socket wait with timeout? e.g. readline with timeout, read with timeout

My thread source code is here

public void run() {

String s=null;

int i=0;

double min=0,max=0,data=0;



s = new String();

while(true){

while(connected){



// graph get data

try {

s = in.readLine();



data = Double.valueOf(s.trim()).doubleValue();

debugLabel.setText("" + data); // print received

if(data>=max) max = data;

if(data<=min) min = data;



// graph plot

if(duration>setduration){

// clear old data

for(int j=0; j<duration;j++)

dataset.getSeries(0).getDataItem(j).setY(0);



// set new duration

duration = setduration;



if(i>=duration) i = 0;

}



if(i>=duration){

if(setduration<=duration){

i=0;

// clear old data

for(int j=0; j<duration;j++)

dataset.getSeries(0).getDataItem(j).setY(0);



} else if(i >= setduration){

i=0;



// clear old data

for(int j=0; j<duration;j++)

dataset.getSeries(0).getDataItem(j).setY(0);



duration = setduration;

} else {

// plot in the case : new series period

series.add(i,data);

Yaxis.setRangeWithMargins(min,max);

dataset.getSeries(0).getDataItem(i).setY(data);

chartPanel.firePropertyChange("w",true,true);

chartPanel.repaint();

i++;

}

} else {

// plot in the case : update old series

Yaxis.setRangeWithMargins(min,max);

dataset.getSeries(0).getDataItem(i).setY(data);

chartPanel.firePropertyChange("a",true,true);

chartPanel.repaint();

i++;

}

} catch (IOException ex) {

ex.printStackTrace();

debugLabel.setText("Connection Timeout");

connected = false;

}





// read sampling period

try {

thread.sleep(0,(int)read_period);

} catch (InterruptedException ex) {

ex.printStackTrace();

}

}





if(!connected){

statusLabel.setText("Reconnecting");

try {

thread.sleep(0,5000);

} catch (InterruptedException ex) {

ex.printStackTrace();

}



initial();

}



}
If you want more information please tell me

Thank you in advanced
ukyo yagamura