Dred -- under the hood

Back to Dred Help Index

Unix Scripts

The scripts dred and ted are very simple, and I don't much care what you decide to call them.
        # usage: dred [switches] files
        exec java -jar $HOME/bin/Dred.jar "$@" &
        # usage: ted [switches] files
        exec java -jar $HOME/bin/Dred.jar --wait "$@" 

Starting in Server Mode

In server mode the program listens for HTTP1.0 requests to start editing sessions. The program can be started in server mode by invoking:

        java -jar Dred.jar --serve[=####] files

If the port number (=####) appears, and the given port is not currently in use, then the program starts serving the current user on that port. If the port number appears, and the given port responds to an inquiry that indicates that a Dred server is operating at that port, then editing sessions are started on that server for the files; otherwise it finds an unused port, starts serving on that, and starts editing sessions on that server for the files.

To discover what port the most-recently activated Dred server is active on use the command

        java -jar Dred.jar --serving
which succeeds (Unix exit 0) and outputs the port number if there is an active server, and fails (Unix exit 1) and outputs 0 otherwise.

Server Requests

An editing request takes the form

        GET /edit?CWD=workingdirectory&FILE=absolutefilename&WAIT=true or false&ENCODING=encoding name

The WAIT and ENCODING parameters can be omitted, in which case they are taken, respectively, to be false, and UTF8.

The server responds by starting an editing session for the given file using the given working directory as the session's effective working directory.

If WAIT is true, then when the session is terminated an HTTP response is generated; otherwise the HTTP response is generated immediately.

The given ENCODING is taken to be the encoding of the file.

The server also honours requests for Dred's documentation files. The Help/Browse Help with Mozilla (etc) menu actions are implemented by aiming the browser at Dred's built-in server port (####), using the command:

        mozilla http://localhost:####/index.html

Logging Server

Dred has an internal event-logging system that is intended to be used when debugging without an IDE. The system can be controlled from a browser. You can start Dred's internal logging server from the File/Preferences/Start Log" menu (you need to provide a port number (####) in the Argument minitext), and connect to it as localhost:####/. You'll get back a panel (implemented as an HTML form) that lets you control the level of detail of the logging output, and lets you inspect the last few thousand logging events incrementally.


It's possible, though not much use, to run Dred in server mode on Windows. By preventing the opening of local ports without administrator permission XP Service pack 2 makes it slightly tedious to do this. The best thing to do (if you are sure you want a proper server and not a pseudo-server) is to allocate a fixed port for Dred and make appropriate arrangements with the administrator to unblock that port. If your administrator wants to know why this is secure, explain that Dred only accepts connections from the host on which it's running.

Bernard Sufrin
$Revision: 113 $
$Date: 2005-06-30 12:29:14 +0100 (Thu, 30 Jun 2005) $