Implements a caller/client for the req node of the req/rep protocol. Sends data to the rep node (executor/server) and returns an Aio, which can be called when the result is required.

  send_mode = c("serial", "raw"),
  recv_mode = c("serial", "character", "complex", "double", "integer", "logical",
    "numeric", "raw"),
  timeout = NULL,
  keep.raw = FALSE



a Context.


an object (if send_mode = 'raw', a vector).


[default 'serial'] whether data will be sent serialized or as a raw vector. Use 'serial' for sending and receiving within R to ensure perfect reproducibility. Use 'raw' for sending vectors of any type (will be converted to a raw byte vector for sending) - essential when interfacing with external applications.


[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.


[default NULL] integer value in milliseconds or NULL, which applies a socket-specific default, usually the same as no timeout. Note that this applies to receiving the result.


[default FALSE] logical flag whether to keep and return the received raw vector along with the converted data.


A 'recvAio' (object of class 'recvAio').


Sending the request and receiving the result are both performed async, hence the function will return immediately with a 'recvAio' object. Access the return value at $data.

This is designed so that the process on the server can run concurrently without blocking the client.

Optionally use call_aio on the 'recvAio' to call (and wait for) the result.

If an error occured in the server process, a nul byte 00 will be received (as $data if 'recv_mode' = 'serial', as $raw otherwise). This allows an error to be easily distinguished from a NULL return value. is_nul_byte can be used to test for a nul byte.


req <- socket("req", listen = "tcp://")
rep <- socket("rep", dial = "tcp://")

ctxq <- context(req)
ctxp <- context(rep)

# works if req and rep are running in parallel in different processes
reply(ctxp, execute = function(x) x + 1, timeout = 10)
#> Warning: 5 | Timed out
#> 'errorValue' int 5 
aio <- request(ctxq, data = 2022, timeout = 10)
#> Warning: 5 | Timed out