Figure 6.1 illustrates the use of three different programs to circumvent the security restrictions put on Java applets by their browsers.
Since the applet is not allowed to connect
directly to the host providing the camera (as described in
section 4.8.2 on
page ), a proxy is needed
on the Web server from which the applet was loaded. The proxy
functions as a gateway, redirecting packets from the camera server to
any applets having announced their interest in the video feed.
Figure 6.1: Three different programs running at
three different hosts: The workaround for Java applet security.
The programs communicate using both TCP and UDP. The reliable, bidirectional TCP connections are used for passing control messages, like setting up and taking down the connection. The UDP ``connection'' is unidirectional. It is used for sending blocks of the image from the producer to the consumer. UDP was chosen for the image blocks to avoid the reliability overhead in TCP. Loosing a few packets is not critical, as the image is continuously updated.
The proxy running on the Web server is the program first started. It waits for incoming TCP connections from a video stream provider, and one or more viewers. When the grabber program is started on the host equipped with the camera, it connects to the proxy using TCP. If the proxy already has a camera feed, it responds with an error code, and shuts down the connection. Otherwise, it binds a local UDP port, and sends the port number to the grabber. Both programs wait, doing nothing until a viewer Java applet connects to the proxy.
When a viewer connects to the proxy using TCP, it may either receive an error code, or a welcome code. In the latter case, it binds a local UDP port, and sends the port number to the proxy. If the applet is the first to connect, the proxy tells the grabber to start the feed by sending a control code using TCP. The grabber sends datagrams containing image blocks to the proxy using the UDP port number received at startup, and the proxy resends all incoming datagrams to all viewers, using their respective UDP port numbers.