I have an applet that accepts data as a stream from a php script using the following code snippet:
The variable dataendpoint actually comes into the applet as a parameter, I am just showing something here for clarity.
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):
Here is the problem: When I leave off the while loop and just let the script spit out the contents of the datafiles and exit, everything works fine and my graph appears immediately in my applet.
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
Code:
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):
Code:
// 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
Comment