| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/nano.R |
| 3 |
\name{nano} |
| 4 |
\alias{nano} |
| 5 |
\title{Create Nano Object} |
| 6 |
\usage{ |
| 7 |
nano( |
| 8 |
protocol = c("bus", "pair", "poly", "push", "pull", "pub", "sub", "req", "rep", |
| 9 |
"surveyor", "respondent"), |
| 10 |
dial = NULL, |
| 11 |
listen = NULL, |
| 12 |
tls = NULL, |
| 13 |
autostart = TRUE |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{protocol}{[default 'bus'] choose protocol - \code{"bus"}, \code{"pair"}, |
| 18 |
\code{"poly"}, \code{"push"}, \code{"pull"}, \code{"pub"}, \code{"sub"}, \code{"req"}, \code{"rep"}, |
| 19 |
\code{"surveyor"}, or \code{"respondent"} - see \link{protocols}.} |
| 20 |
|
| 21 |
\item{dial}{(optional) a URL to dial, specifying the transport and address as |
| 22 |
a character string e.g. 'inproc://anyvalue' or 'tcp://127.0.0.1:5555' (see |
| 23 |
\link{transports}).} |
| 24 |
|
| 25 |
\item{listen}{(optional) a URL to listen at, specifying the transport and |
| 26 |
address as a character string e.g. 'inproc://anyvalue' or |
| 27 |
'tcp://127.0.0.1:5555' (see \link{transports}).} |
| 28 |
|
| 29 |
\item{tls}{[default NULL] for secure tls+tcp:// or wss:// connections only, |
| 30 |
provide a TLS configuration object created by \code{\link[=tls_config]{tls_config()}}.} |
| 31 |
|
| 32 |
\item{autostart}{[default TRUE] whether to start the dialer/listener. Set |
| 33 |
to FALSE if setting configuration options on the dialer/listener as it is |
| 34 |
not generally possible to change these once started. For dialers only: set |
| 35 |
to NA to start synchronously - this is less resilient if a connection is |
| 36 |
not immediately possible, but avoids subtle errors from attempting to use |
| 37 |
the socket before an asynchronous dial has completed.} |
| 38 |
} |
| 39 |
\value{ |
| 40 |
A nano object of class 'nanoObject'. |
| 41 |
} |
| 42 |
\description{ |
| 43 |
Create a nano object, encapsulating a Socket, Dialers/Listeners and |
| 44 |
associated methods. |
| 45 |
} |
| 46 |
\details{ |
| 47 |
This function encapsulates a Socket, Dialer and/or Listener, and its |
| 48 |
associated methods. |
| 49 |
|
| 50 |
The Socket may be accessed by \verb{$socket}, and the Dialer or Listener by |
| 51 |
\verb{$dialer[[1]]} or \verb{$listener[[1]]} respectively. |
| 52 |
|
| 53 |
The object's methods may be accessed by \code{$} e.g. \verb{$send()} or \verb{$recv()}. |
| 54 |
These methods mirror their functional equivalents, with the same arguments |
| 55 |
and defaults, apart from that the first argument of the functional equivalent |
| 56 |
is mapped to the object's encapsulated socket (or context, if active) and |
| 57 |
does not need to be supplied. |
| 58 |
|
| 59 |
More complex network topologies may be created by binding further dialers or |
| 60 |
listeners using the object's \verb{$dial()} and \verb{$listen()} methods. The new |
| 61 |
dialer/listener will be attached to the object e.g. if the object already has |
| 62 |
a dialer, then at \verb{$dialer[[2]]} etc. |
| 63 |
|
| 64 |
Note that \verb{$dialer_opt()} and \verb{$listener_opt()} methods will be available |
| 65 |
once dialers/listeners are attached to the object. These methods get or apply |
| 66 |
settings for all dialers or listeners equally. To get or apply settings for |
| 67 |
individual dialers/listeners, access them directly via \verb{$dialer[[2]]} or |
| 68 |
\verb{$listener[[2]]} etc. |
| 69 |
|
| 70 |
The methods \verb{$opt()}, and also \verb{$dialer_opt()} or \verb{$listener_opt()} as may be |
| 71 |
applicable, will get the requested option if a single argument \code{name} is |
| 72 |
provided, and will set the value for the option if both arguments \code{name} and |
| 73 |
\code{value} are provided. |
| 74 |
|
| 75 |
For Dialers or Listeners not automatically started, the \verb{$dialer_start()} or |
| 76 |
\verb{$listener_start()} methods will be available. These act on the most recently |
| 77 |
created Dialer or Listener respectively. |
| 78 |
|
| 79 |
For applicable protocols, new contexts may be created by using the |
| 80 |
\verb{$context_open()} method. This will attach a new context at \verb{$context} as |
| 81 |
well as a \verb{$context_close()} method. While a context is active, all object |
| 82 |
methods use the context rather than the socket. A new context may be created |
| 83 |
by calling \verb{$context_open()}, which will replace any existing context. It is |
| 84 |
only necessary to use \verb{$context_close()} to close the existing context and |
| 85 |
revert to using the socket. |
| 86 |
} |
| 87 |
\examples{ |
| 88 |
nano <- nano("bus", listen = "inproc://nanonext") |
| 89 |
nano |
| 90 |
nano$socket |
| 91 |
nano$listener[[1]] |
| 92 |
|
| 93 |
nano$opt("send-timeout", 1500) |
| 94 |
nano$opt("send-timeout") |
| 95 |
|
| 96 |
nano$listen(url = "inproc://nanonextgen") |
| 97 |
nano$listener |
| 98 |
|
| 99 |
nano1 <- nano("bus", dial = "inproc://nanonext") |
| 100 |
nano$send("example test", mode = "raw") |
| 101 |
nano1$recv("character") |
| 102 |
|
| 103 |
nano$close() |
| 104 |
nano1$close() |
| 105 |
|
| 106 |
} |