Learn R Programming

nanonext (version 0.2.0)

recv: Receive

Description

Receive data over a Socket.

Usage

recv(
  socket,
  mode = c("serial", "character", "complex", "double", "integer", "logical", "numeric",
    "raw"),
  block = FALSE,
  keep.raw = TRUE
)

Arguments

socket

a Socket.

mode

[default 'serial'] mode of vector to be received - one of 'serial', 'character', 'complex', 'double', 'integer', 'logical', 'numeric', or 'raw'. The default 'serial' means a serialised R object, for the other modes, the raw vector received will be converted into the respective mode.

block

[default FALSE] logical flag whether to block until successful or return immediately even if unsuccessful (e.g. nothing to receive).

keep.raw

[default TRUE] logical flag whether to keep the received raw vector (useful for verification e.g. via hashing). If FALSE, will return the converted data only.

Value

Named list of 2 elements: 'raw' containing the received raw vector and 'data' containing the converted R object, or else the converted R object if 'keep.raw' is set to FALSE.

Details

In case of an error in unserialisation or data conversion, the function will still return the received raw vector to allow the data to be recovered.

Examples

Run this code
# NOT RUN {
s1 <- socket("bus", listen = "inproc://nanonext")
s2 <- socket("bus", dial = "inproc://nanonext")

send(s1, data.frame(a = 1, b = 2))
res <- recv(s2)
res
send(s1, data.frame(a = 1, b = 2), echo = FALSE)
recv(s2, keep.raw = FALSE)

send(s1, c(1.1, 2.2, 3.3), mode = "raw")
res <- recv(s2, mode = "double")
res
send(s1, "example message", mode = "raw", echo = FALSE)
recv(s2, mode = "character", keep.raw = FALSE)

close(s1)
close(s2)

# }

Run the code above in your browser using DataLab