Information about what MCHTTPd is and how it works |
To request data from a server, a client creates a socket to the server on the specified port. When the socket connects, the client sends a request for the server to do something by writing to the socket. In the case of HTTP, the client requests a file or sends in data from a form which is to be processed (typically by a Common Gateway Interface (CGI) application) and the file or result is returned to the client. There are two ways a MetaCard application can transfer data with socket. With the first method the command does not return until all the data has been read from or written two the socket. This method is also known as "blocking I/O" and is best for short messages or fast networks. With the second method, the read or write is done in the background and a message sent when the operation is complete. This is a much more efficient method because other scripts can run while the data is being moved over the socket. This is the method that all servers should use, and is the method used by MCHTTPd. When a read or write operation has completed and a message sent, one or two parameters are passed with it. The first parameter is the address of the system at the other end of the socket. The second parameter, passed only when a read operation has completed, is the actual data from the other system. The basic flow in MCHTTPd is for the server to wait for a connection, start a read on that connection, process the request passed in the second parameter when the read completes, and write the answer to the client specified in the first parameter. For html files, which are retrieved with the HTTP GET command, only the first line of the request is really needed since it contains the file name the client wants. For the HTTP POST command, all of the data is required since the data the client is uploading is on lines after the first one. If a large amount of data is being posted to the server, more than one read command may be necessary to get it all (the total size is included in the header information). Since a server typically works with many files, a "root" directory is typically defined for it when it is installed. MCHTTPd gets its "root" directory from the directory it is installed in. In their root directories, HTTP servers usually have an "html" directory where the web pages and images are stored and a "cgi-bin" directory for scripts which process data from HTML forms (note that .mt files only work on UNIX OSes). MCHTTPd has a third directory, "stacks-bin", which contains stacks whose scripts it can call with start using instead of typical cgis.This improves performance considerably and also makes scripting server-side applications much easier. The MCHTTPd distribution contains a trivial example of such a stack. Please keep in mind that MCHTTPd is a work in progress and that many new features will be added as development continues. You are encouraged to use the package as is, or to make modifications to it to suit your particular needs. Feedback and copies of any modifications you make are welcome at support@metacard.com. |