Description Usage Arguments Details Note Author(s) See Also
A R socket server is listening for command send by clients to a TCP port. This server is implemented in Tcl/Tk, using the powerful 'socket' command. Since it runs in the separate tcltk event loop, it is not blocking R, and it runs in the background; the user can still enter commands at the R prompt while one or several R socket servers are running and even, possibly, processing socket clients requests.
1 2 3 | startSocketServer(port = 8888, server.name = "Rserver", procfun = processSocket,
secure = FALSE, local = !secure)
stopSocketServer(port = 8888)
|
port |
the TCP port of the R socket server. |
server.name |
the internal name of this server. |
procfun |
the function to use to process client's commands. By default,
it is |
secure |
do we start a secure (TLS) server? (not implemented yet) |
local |
if |
One can write a different procfun
function than the default one for
special servers. That function must accept one argument (a string with the
command send by the client) and it must return a character string containing
the result of the computation.
This server is currently synchronous in the processing of the command. However, neither R, nor the client are blocked during exchange of data (communication is asynchronous).
Note also that socket numbers are reused, and corresponding configurations
are not deleted from one connection to the other. So, it is possible for
a client to connect/disconnect several times and continue to work with the
same configuration (in particular, the multiline code submitted line by
line) if every command starts with <<<id=myID>>>
where myID
is
an alphanumeric (unique) identifier. This property is call a stateful server.
Take care! The R server never checks uniqueness of this identifier. You are
responsible to use one that would not intefere with other, concurrent, clients
connected to the same server.
For trials and basic testings of the R socket server, you can use the Tcl script SimpleClient.Tcl. See the ReadMe.txt file in the /etc/ subdirectory of the svSocket package folder. Also, in the source of the svSocket package you will find testCLI.R, a script to torture test CLI for R (console).
Philippe Grosjean (phgrosjean@sciviews.org)
processSocket
, startHttpServer
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.