Learn R Programming

svSocket (version 1.1.0)

start_socket_server: Start and stop a R socket server

Description

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.

Usage

start_socket_server(
  port = 8888,
  server_name = "Rserver",
  procfun = process_socket_server,
  secure = FALSE,
  local = !secure
)

startSocketServer( port = 8888, server_name = "Rserver", procfun = process_socket_server, secure = FALSE, local = !secure )

stop_socket_server(port = 8888)

stopSocketServer(port = 8888)

Arguments

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 process_socket_server().

secure

do we start a secure (TLS) server? (not implemented yet)

local

if TRUE, accept only connections from local clients, i.e., from clients with IP address 127.0.0.1. Set by default if the server is not secure.

Details

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 interfere 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).

See Also

process_socket_server(), send_socket_clients()