Expand|Select|Wrap|Line Numbers
- String dataendpoint = "http://phpfunction.php";
- URL url = new URL(dataendpoint);
- InputStream is = url.openStream();
- String line;
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr,0);
- while ((line = br.readLine()) != null) {
- // my code here to handle each line of data which prepares it for
- // showing on a line graph.
- }
The intention is to have PHP read existing datafiles and produce the initial data for this applet which is then plotted on a graph in the browser. After this initial data is shown, the data will then continue to be streamed as new data is produced. So the PHP code is like this (shown as pseudocode):
Expand|Select|Wrap|Line Numbers
- // open data files, read lines, and send to standard output using echo
- // flush data using ob_flush() and flush() calls
- while (1) {
- sleep(30);
- // get new data, if any, then send to standard output
- // flush buffers again
- }
With the while loop, however, nothing appears for a very long time delay. After this time delay, everything works fine, and my graph is updated every 30 seconds when new data appears, just as I want it to.
The problem is how to avoid this long delay time which is occurring? I have done a Wireshark trace and see that the data from the files is being sent immediately to the browser. Putting print statements in my Java code shows me that the code is blocking at this line:
InputStream is = url.openStream();
Can anyone tell me what is happening here and what to do about it?
Thanks for any help!!!
Steve, Denmark