| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/sendrecv.R |
| 3 |
\name{recv} |
| 4 |
\alias{recv} |
| 5 |
\title{Receive} |
| 6 |
\usage{ |
| 7 |
recv( |
| 8 |
con, |
| 9 |
mode = c("serial", "character", "complex", "double", "integer", "logical", "numeric", |
| 10 |
"raw", "string"), |
| 11 |
block = NULL |
| 12 |
) |
| 13 |
} |
| 14 |
\arguments{ |
| 15 |
\item{con}{a Socket, Context or Stream.} |
| 16 |
|
| 17 |
\item{mode}{[default 'serial'] character value or integer equivalent - one |
| 18 |
of \code{"serial"} (1L), \code{"character"} (2L), \code{"complex"} (3L), \code{"double"} (4L), |
| 19 |
\code{"integer"} (5L), \code{"logical"} (6L), \code{"numeric"} (7L), \code{"raw"} (8L), or |
| 20 |
\code{"string"} (9L). The default \code{"serial"} means a serialised R object; for |
| 21 |
the other modes, received bytes are converted into the respective mode. |
| 22 |
\code{"string"} is a faster option for length one character vectors. For |
| 23 |
Streams, \code{"serial"} will default to \code{"character"}.} |
| 24 |
|
| 25 |
\item{block}{[default NULL] which applies the connection default (see |
| 26 |
section 'Blocking' below). Specify logical \code{TRUE} to block until successful |
| 27 |
or \code{FALSE} to return immediately even if unsuccessful (e.g. if no |
| 28 |
connection is available), or else an integer value specifying the maximum |
| 29 |
time to block in milliseconds, after which the operation will time out.} |
| 30 |
} |
| 31 |
\value{ |
| 32 |
The received data in the \code{mode} specified. |
| 33 |
} |
| 34 |
\description{ |
| 35 |
Receive data over a connection (Socket, Context or Stream). |
| 36 |
} |
| 37 |
\section{Errors}{ |
| 38 |
|
| 39 |
|
| 40 |
In case of an error, an integer 'errorValue' is returned (to be |
| 41 |
distiguishable from an integer message value). This can be verified using |
| 42 |
\code{\link[=is_error_value]{is_error_value()}}. |
| 43 |
|
| 44 |
If an error occurred in unserialization or conversion of the message data to |
| 45 |
the specified mode, a raw vector will be returned instead to allow recovery |
| 46 |
(accompanied by a warning). |
| 47 |
} |
| 48 |
|
| 49 |
\section{Blocking}{ |
| 50 |
|
| 51 |
|
| 52 |
For Sockets and Contexts: the default behaviour is non-blocking with |
| 53 |
\code{block = FALSE}. This will return immediately with an error if no messages |
| 54 |
are available. |
| 55 |
|
| 56 |
For Streams: the default behaviour is blocking with \code{block = TRUE}. This will |
| 57 |
wait until a message is received. Set a timeout to ensure that the function |
| 58 |
returns under all scenarios. As the underlying implementation uses an |
| 59 |
asynchronous receive with a wait, it is recommended to set a small positive |
| 60 |
value for \code{block} rather than \code{FALSE}. |
| 61 |
} |
| 62 |
|
| 63 |
\examples{ |
| 64 |
s1 <- socket("pair", listen = "inproc://nanonext") |
| 65 |
s2 <- socket("pair", dial = "inproc://nanonext") |
| 66 |
|
| 67 |
send(s1, data.frame(a = 1, b = 2)) |
| 68 |
res <- recv(s2) |
| 69 |
res |
| 70 |
send(s1, data.frame(a = 1, b = 2)) |
| 71 |
recv(s2) |
| 72 |
|
| 73 |
send(s1, c(1.1, 2.2, 3.3), mode = "raw") |
| 74 |
res <- recv(s2, mode = "double", block = 100) |
| 75 |
res |
| 76 |
send(s1, "example message", mode = "raw") |
| 77 |
recv(s2, mode = "character") |
| 78 |
|
| 79 |
close(s1) |
| 80 |
close(s2) |
| 81 |
|
| 82 |
req <- socket("req", listen = "inproc://nanonext") |
| 83 |
rep <- socket("rep", dial = "inproc://nanonext") |
| 84 |
|
| 85 |
ctxq <- context(req) |
| 86 |
ctxp <- context(rep) |
| 87 |
send(ctxq, data.frame(a = 1, b = 2), block = 100) |
| 88 |
recv(ctxp, block = 100) |
| 89 |
|
| 90 |
send(ctxq, c(1.1, 2.2, 3.3), mode = "raw", block = 100) |
| 91 |
recv(ctxp, mode = "double", block = 100) |
| 92 |
|
| 93 |
close(req) |
| 94 |
close(rep) |
| 95 |
|
| 96 |
} |
| 97 |
\seealso{ |
| 98 |
\code{\link[=recv_aio]{recv_aio()}} for asynchronous receive. |
| 99 |
} |