Learn R Programming

svSocket (version 0.9-55)

processSocket: The function that processes a command coming from the socket

Description

This is the default R function called each time data is send by a client through a socket. It is possible to customize this function and to use customized versions for particular R socket servers.

Usage

processSocket(msg, socket, serverport, ...)

Arguments

msg
the message send by the client, to be processed.
socket
the client socket identifier, as in getSocketClients(). This is passed by the calling function and can be used internally.
serverport
the port on which the server is running, this is passed by the calling function and can be used internally.
...
anything you want to pass to processSocket(), but it needs to rework startServerSocket() to use it).

Value

  • The results of processing msg in a character string vector.

concept

stateful socket server interprocess communication

See Also

startSocketServer, sendSocketClients, parSocket, Parse, captureAll

Examples

Run this code
## A simple REPL (R eval/process loop) using basic features of processSocket()
repl <- function ()
{
	pars <- parSocket("repl", "", bare = FALSE)  # Parameterize the loop
	cat("Enter R code, hit <CTRL-C> or <ESC> to exit\n> ")   # First prompt
	repeat {
		entry <- readLines(n = 1) 				 # Read a line of entry
		if (entry == "") entry <- "<<<esc>>>"    # Exit from multiline mode
		cat(processSocket(entry, "repl", ""))    # Process the entry
	}
}
repl()

Run the code above in your browser using DataLab