Learn R Programming

nanonext (version 0.2.0)

recv_ctx: Receive over Context

Description

Receive data over a Context.

Usage

recv_ctx(
  context,
  mode = c("serial", "character", "complex", "double", "integer", "logical", "numeric",
    "raw"),
  timeout,
  keep.raw = TRUE
)

Arguments

context

a Context.

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.

timeout

in ms. If unspecified, a socket-specific default timeout will be used.

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

Will block while awaiting the receive operation to complete. Set a timeout to ensure that the function returns under all scenarios.

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 {
req <- socket("req", listen = "inproc://nanonext")
rep <- socket("rep", dial = "inproc://nanonext")

ctxq <- context(req)
ctxp <- context(rep)
send_ctx(ctxq, data.frame(a = 1, b = 2), timeout = 100)
recv_ctx(ctxp, timeout = 100)

send_ctx(ctxq, c(1.1, 2.2, 3.3), mode = "raw", timeout = 100)
recv_ctx(ctxp, mode = "double", timeout = 100)

close(req)
close(rep)

# }

Run the code above in your browser using DataLab