Log In [secure]
Log In [http]
A Terminal Anywhere
This page describes deployment of the current stable version of Anyterm; the development version (which is in practice probably at least as stable) works slightly differently. This page will be updated when what's currently the development version is blessed as "stable".
When the page loads it sends an "open" request. This makes the Apache module create a new emulated terminal and spawn a new process using forkpty() containing the shell or other program. It communicates with the program using a pseudo-terminal.
In general Apache has many processes with many threads all handling requests. Anyterm XmlHTTP requests can arrive in any of these processes / threads. Anyterm creates its own "back end" process to run the terminal emulation code and this communicates with the request handling processes / threads using shared memory. The first time that an Anyterm request is received by a process it attaches itself to this shared memory segment.
When you press a key an XmlHTTP request is sent. If you press more keys before that request has completed they are batched up. In the Apache module these keypresses are sent to the back-end process using a fifo in the shared memory. They are then passed on to the program via the pseudo-terminal.
The back-end process has one thread for each sub-process which receives its output and invokes the terminal emulation code to updates the screen image, which is stored in the shared memory, along with a dirty flag.
As soon as it starts the browser sends a request asking for new screen content. If the screen has changed the module returns the differences immediately, but if nothing has changed it will wait on the dirty flag for up to 10 seconds waiting for changes before returning an unchanged screen image. As soon as this new screen data is returned the browser makes another request. In this way a virtual "push" channel is implemented over "pull" HTTP.
To reduce network bandwidth, differences between one screen and the next are detected using an algorithm similar to the one used by the diff program. See the source code for details. The data returned to the browser is in the form of an "edit script", i.e. a sequence of instructions telling it how to change its current content to match the new screen.
Multiple simultaneous sessions are possible. Each open request returns a random 64-bit session identifier that is used in subsequent communications. Privacy relies on this random identifier being unguessable.
Sessions can be explicitly closed by pressing the "close" button. They will also close automatically if there has been no activity for 30 seconds; this will happen if the user closes the browser window or navigates away from the page. Note that viewing the page without pressing any keys does not trigger this timeout since the display is still being updated every 10 seconds.