I have simple server-client application. There is an option, which client can send to the server, to read generated data.
void getManyFromServer(int numberOfGets){
try{
for(int i=0;i<numberOfGets;i++){
fromServer = sockIn.readLine();
fromServer+="\n";
textArea.append(fromServer);
}
} catch(IOException exc){
/*...*/
}
}
As you can see, I want to read data 10 times, because server will generate 10 different numbers, every 3s:
Random randomGenerator = new Random();
double MEAN = 4.0f;
double VARIANCE = 0.01f;
for(int i=0;i<10;i++){
out.println(Double.toString(MEAN + randomGenerator.nextGaussian()* VARIANCE));
try{
Thread.sleep(3000);
} catch(InterruptedException e){
/*...*/
}
The problem is - clients waits until all "out.println" are finished and then prints everything at once in textArea.
How can I simulate 3s delay between writing data into textArea?