| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/sendrecv.R |
| 3 |
\name{send} |
| 4 |
\alias{send} |
| 5 |
\title{Send} |
| 6 |
\usage{ |
| 7 |
send(con, data, mode = c("serial", "raw"), block = NULL, pipe = 0L) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{con}{a Socket, Context or Stream.} |
| 11 |
|
| 12 |
\item{data}{an object (a vector, if \code{mode = "raw"}).} |
| 13 |
|
| 14 |
\item{mode}{[default 'serial'] character value or integer equivalent - |
| 15 |
either \code{"serial"} (1L) to send serialised R objects, or \code{"raw"} (2L) to |
| 16 |
send atomic vectors of any type as a raw byte vector. For Streams, \code{"raw"} |
| 17 |
is the only option and this argument is ignored.} |
| 18 |
|
| 19 |
\item{block}{[default NULL] which applies the connection default (see |
| 20 |
section 'Blocking' below). Specify logical \code{TRUE} to block until successful |
| 21 |
or \code{FALSE} to return immediately even if unsuccessful (e.g. if no |
| 22 |
connection is available), or else an integer value specifying the maximum |
| 23 |
time to block in milliseconds, after which the operation will time out.} |
| 24 |
|
| 25 |
\item{pipe}{[default 0L] only applicable to Sockets using the 'poly' |
| 26 |
protocol, an integer pipe ID if directing the send via a specific pipe.} |
| 27 |
} |
| 28 |
\value{ |
| 29 |
An integer exit code (zero on success). |
| 30 |
} |
| 31 |
\description{ |
| 32 |
Send data over a connection (Socket, Context or Stream). |
| 33 |
} |
| 34 |
\section{Blocking}{ |
| 35 |
|
| 36 |
|
| 37 |
For Sockets and Contexts: the default behaviour is non-blocking with |
| 38 |
\code{block = FALSE}. This will return immediately with an error if the message |
| 39 |
could not be queued for sending. Certain protocol / transport combinations |
| 40 |
may limit the number of messages that can be queued if they have yet to be |
| 41 |
received. |
| 42 |
|
| 43 |
For Streams: the default behaviour is blocking with \code{block = TRUE}. This will |
| 44 |
wait until the send has completed. Set a timeout to ensure that the function |
| 45 |
returns under all scenarios. As the underlying implementation uses an |
| 46 |
asynchronous send with a wait, it is recommended to set a small positive |
| 47 |
value for \code{block} rather than \code{FALSE}. |
| 48 |
} |
| 49 |
|
| 50 |
\section{Send Modes}{ |
| 51 |
|
| 52 |
|
| 53 |
The default mode \code{"serial"} sends serialised R objects to ensure perfect |
| 54 |
reproducibility within R. When receiving, the corresponding mode \code{"serial"} |
| 55 |
should be used. Custom serialization and unserialization functions for |
| 56 |
reference objects may be enabled by the function \code{\link[=serial_config]{serial_config()}}. |
| 57 |
|
| 58 |
Mode \code{"raw"} sends atomic vectors of any type as a raw byte vector, and must |
| 59 |
be used when interfacing with external applications or raw system sockets, |
| 60 |
where R serialization is not in use. When receiving, the mode corresponding |
| 61 |
to the vector sent should be used. |
| 62 |
} |
| 63 |
|
| 64 |
\examples{ |
| 65 |
pub <- socket("pub", dial = "inproc://nanonext") |
| 66 |
|
| 67 |
send(pub, data.frame(a = 1, b = 2)) |
| 68 |
send(pub, c(10.1, 20.2, 30.3), mode = "raw", block = 100) |
| 69 |
|
| 70 |
close(pub) |
| 71 |
|
| 72 |
req <- socket("req", listen = "inproc://nanonext") |
| 73 |
rep <- socket("rep", dial = "inproc://nanonext") |
| 74 |
|
| 75 |
ctx <- context(req) |
| 76 |
send(ctx, data.frame(a = 1, b = 2), block = 100) |
| 77 |
|
| 78 |
msg <- recv_aio(rep, timeout = 100) |
| 79 |
send(ctx, c(1.1, 2.2, 3.3), mode = "raw", block = 100) |
| 80 |
|
| 81 |
close(req) |
| 82 |
close(rep) |
| 83 |
|
| 84 |
} |
| 85 |
\seealso{ |
| 86 |
\code{\link[=send_aio]{send_aio()}} for asynchronous send. |
| 87 |
} |