Learn R Programming

R.rsp (version 0.46.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:

appendRootPathsAppends and inserts new paths to the list of known root directories.
as.characterReturns a short string describing the HTTP daemon.
finalize-
getConfigRetrieves the server's 'config' structure from Tcl.
getCount-
getDefaultFilenamePatternGets the default filename pattern to be loaded by the HTTP daemon.
getHttpRequestGets the HTTP request.
getPortGets the socket port of the HTTP daemon.
getRootPathsGets the root directories of the HTTP daemon.
insertRootPaths-
isStartedChecks if the HTTP daemon is started.
openUrlStarts the HTTP daemon and launches the specified URL.
processRspProcesses an RSP page.
restartRestarts the HTTP daemon.
setCount-
setRootPathsSets a new set of root directories for the HTTP daemon.
sourceTclLoads the Tcl source for the HTTP daemon into R.
startStarts the HTTP daemon.
startHelpStarts the HTTP daemon and launches the help page.
terminateTerminates the HTTP daemon.
writeResponseWrites 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

Author

Henrik Bengtsson

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.file("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
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 DataLab