Forum Moderators: open

Message Too Old, No Replies

Problems with web cam page

         

shadowman

3:50 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



While trying to make an auto refreshing webcam page, I encountered the following problems:

1. When a client is currently downloading the JPEG image file, the file is locked against write access, and the program which captures the images from the camera and rewrites the JPEG file halts with a file access error.

2. When the capture program is rewriting the JPEG image file, it's locked against read/write access and if a client's web browser happens to refresh at that moment, they get a broken image link icon since the HTTP daemon is unable to read the file at that time.

3. Some people have reported that occasionally the picture stops updating, and I too have encountered this the odd time with Opera 6.05. I had to right-click the image and select Reload Image in order to view the updated one. This leads me to believe web browsers are still sometimes reading from the cache even if the updated picture is different.

Any suggestions to get around these problems?

shadowman

3:56 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



I'm considering one method I thought of to get around these problems, but it gets complicated. I'm thinking perhaps a CGI script is the way to go?

This is what I propose:
Configure the system so that the camera software writes to a JPEG file which is never actually sent to the clients. When each client's browser refreshes, a CGI script is called to read the source JPEG file and copy it to a second file which is sent to the client. The CGI script would be programmed to handle the source file locking, perhaps retrying every 0.5 seconds if the file is locked (ie when the camera software is currently updating the image).

To handle the caching problem, I figure if the CGI program writes to a randomly named JPEG file on each refresh, the client web browser will be forced to download the image rather than just display it from the local cache. This would also mean a JPEG image is created for each individual client, and the HTTP daemon would never attempt to send a file that's currently being written (and therefore locked read/write).

To prevent the server from filling up with endless random old images, the HTML page generated by the CGI would contain a parameter value equal to the random JPEG filename. So next time the page refreshes, the CGI program can delete the old file and generate another random image. A potential problem I see with this is if a client leaves without "logging out" from the web site, the latest JPEG file will never be cleared because no form is submitted instructing the CGI script to delete the file. To resolve this, the only solution I can think of is to have a scheduled daemon that runs maybe every hour, and deletes any JPEG images with an old file creation date.

Is such a system feasible? Or even possible? Or is there a much simpler solution that would work?

The CGI solution leads to an important question: Is there any way to make a web page form auto submit to a CGI based on a timeout? Something similar to the <META HTTP-EQUIV="Refresh"> tag, only in this case the form data has to be submitted the CGI program rather than simply reloading the blank form.

korkus2000

3:56 pm on Dec 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using a server-side language?

shadowman

4:21 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



Right now, everything is done with static HTML files. No PHP, no CGI. Just a file called index.html with an auto refresh meta tag, and the camera software is configured to keep rewriting a JPEG image file every 15 seconds.