Learn R Programming

fame (version 1.13)

sendSocketObject: Send and Receive RObjects through Sockets

Description

These functions allow Rsessions on different machines to send Robjects to each other. Consider two Rsessions running on (possibly) different machines. Call the sessions R1 and R2, with R1 running on somehost.somewhere.com. To send an object from R1 to R2, the sequence of events goes like this:

1. R1 invokes receiveSocketObject(NNNNN), where NNNNN is an available port number on R1's localhost. (Use availablePort to find a port number.) The R1 session hangs until:

2. R2 invokes sendSocketObject(object, "somehost.somewhere.com", NNNNN) to send object to R1. If R1 is not listening on port NNNNN already, this operation will hang R2 until R1 invokes receiveSocketObject(NNNNN) to start listening there.

3. R1 and R2 both return after object has been sent, with receiveSocketObject on R1 returning the object that was sent.

Usage

sendSocketObject(object, host, port)
receiveSocketObject(port)

Arguments

object
an Robject
host
DNS name of the host to which object is being sent
port
TCP port number on the receiving end

Value

  • receiveSocketObject() returns the object sent.

Details

sendSocketObject opens a blocking binary client socket connection to the given host and port, serializes object onto the connection, then closes it.

receiveSocketObject listens on a blocking binary server socket and returns the Robject sent over it.

See Also

availablePort to find a port number, and startRemoteServer to run a server that accepts Rcommands over a socket and returns the resulting Robjects