R.rsp (version 0.44.0)

HttpDaemon: The HttpDaemon class

Description

Package: R.rsp Class HttpDaemon

Object ~~| ~~+--HttpDaemon

Directly known subclasses:

public static class HttpDaemon extends Object

A minimalistic HTTP daemon (web server) that also preprocesses RSP.

Usage

HttpDaemon(...)

Arguments

...

Not used.

Fields and Methods

Methods:

appendRootPaths Appends and inserts new paths to the list of known root directories.
as.character Returns a short string describing the HTTP daemon.
finalize -
getConfig Retrieves the server's 'config' structure from Tcl.
getCount -
getDefaultFilenamePattern Gets the default filename pattern to be loaded by the HTTP daemon.
getHttpRequest Gets the HTTP request.
getPort Gets the socket port of the HTTP daemon.
getRootPaths Gets the root directories of the HTTP daemon.
insertRootPaths -
isStarted Checks if the HTTP daemon is started.
openUrl Starts the HTTP daemon and launches the specified URL.
processRsp Processes an RSP page.
restart Restarts the HTTP daemon.
setCount -
setRootPaths Sets a new set of root directories for the HTTP daemon.
sourceTcl Loads the Tcl source for the HTTP daemon into R.
start Starts the HTTP daemon.
startHelp Starts the HTTP daemon and launches the help page.
terminate Terminates the HTTP daemon.
writeResponse Writes a string to the HTTP output connection.

Methods inherited from Object: $, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clearLookupCache, clone, detach, equals, extend, finalize, getEnvironment, getFieldModifier, getFieldModifiers, getFields, getInstantiationTime, getStaticInstance, hasField, hashCode, ll, load, names, objectSize, print, save

Details

The actual server is written in Tcl such that it runs in a non-blocking mode, which means that the R prompt will be available for other things. This class is tightly coupled with the source code of the Tcl script.

For security reasons, the server only accept connections from the local host (127.0.0.1). This lowers the risk for external computers to gain access to the R session. This is asserted by the accept_connect Tcl procedure in r-httpd.tcl (located in system("tcl/", package="R.rsp")). If access from other hosts are wanted, then this procedure needs to be modified.

The Tcl server was written by Steve Uhlers, and later adopted for R by Philippe Grosjean and Tom Short (Rpad package author) [1].

References

[1] Rpad package, Tom Short, 2005.

Examples

Run this code
# NOT RUN {
if (interactive()) {
  if (!HttpDaemon$isStarted()) {
    # Start the web server
    rootPath <- system.file("rsp", package="R.rsp")
    HttpDaemon$start(rootPath=rootPath, port=8074, default="^index[.](html|.*)$")
  }
 
  browseURL("http://127.0.0.1:8074/")
}
# }

Run the code above in your browser using DataCamp Workspace