| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/listdial.R |
| 3 |
\name{listen} |
| 4 |
\alias{listen} |
| 5 |
\title{Listen to an Address from a Socket} |
| 6 |
\usage{ |
| 7 |
listen( |
| 8 |
socket, |
| 9 |
url = "inproc://nanonext", |
| 10 |
tls = NULL, |
| 11 |
autostart = TRUE, |
| 12 |
fail = c("warn", "error", "none") |
| 13 |
) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{socket}{a Socket.} |
| 17 |
|
| 18 |
\item{url}{[default 'inproc://nanonext'] a URL to dial, specifying the |
| 19 |
transport and address as a character string e.g. 'inproc://anyvalue' or |
| 20 |
'tcp://127.0.0.1:5555' (see \link{transports}).} |
| 21 |
|
| 22 |
\item{tls}{[default NULL] for secure tls+tcp:// or wss:// connections only, |
| 23 |
provide a TLS configuration object created by \code{\link[=tls_config]{tls_config()}}.} |
| 24 |
|
| 25 |
\item{autostart}{[default TRUE] whether to start the listener. Set to FALSE |
| 26 |
if setting configuration options on the listener as it is not generally |
| 27 |
possible to change these once started.} |
| 28 |
|
| 29 |
\item{fail}{[default 'warn'] failure mode - a character value or integer |
| 30 |
equivalent, whether to warn (1L), error (2L), or for none (3L) just return |
| 31 |
an 'errorValue' without any corresponding warning.} |
| 32 |
} |
| 33 |
\value{ |
| 34 |
Invisibly, an integer exit code (zero on success). A new Listener |
| 35 |
(object of class 'nanoListener' and 'nano') is created and bound to the |
| 36 |
Socket if successful. |
| 37 |
} |
| 38 |
\description{ |
| 39 |
Creates a new Listener and binds it to a Socket. |
| 40 |
} |
| 41 |
\details{ |
| 42 |
To view all Listeners bound to a socket use \verb{$listener} on the socket, |
| 43 |
which returns a list of Listener objects. To access any individual Listener |
| 44 |
(e.g. to set options on it), index into the list e.g. \verb{$listener[[1]]} |
| 45 |
to return the first Listener. |
| 46 |
|
| 47 |
A listener is an external pointer to a listener object, which accepts |
| 48 |
incoming connections. A given listener object may have many connections at |
| 49 |
the same time, much like an HTTP server can have many connections to multiple |
| 50 |
clients simultaneously. |
| 51 |
} |
| 52 |
\section{Further details}{ |
| 53 |
|
| 54 |
|
| 55 |
Dialers and Listeners are always associated with a single socket. A given |
| 56 |
socket may have multiple Listeners and/or multiple Dialers. |
| 57 |
|
| 58 |
The client/server relationship described by dialer/listener is completely |
| 59 |
orthogonal to any similar relationship in the protocols. For example, a rep |
| 60 |
socket may use a dialer to connect to a listener on an req socket. This |
| 61 |
orthogonality can lead to innovative solutions to otherwise challenging |
| 62 |
communications problems. |
| 63 |
|
| 64 |
Any configuration options on the dialer/listener should be set by \code{\link[=opt<-]{opt<-()}} |
| 65 |
before starting the dialer/listener with \code{\link[=start]{start()}}. |
| 66 |
|
| 67 |
Dialers/Listeners may be destroyed by \code{\link[=close]{close()}}. They are also closed when |
| 68 |
their associated socket is closed. |
| 69 |
} |
| 70 |
|
| 71 |
\examples{ |
| 72 |
socket <- socket("req") |
| 73 |
listen(socket, url = "inproc://nanolisten", autostart = FALSE) |
| 74 |
socket$listener |
| 75 |
start(socket$listener[[1]]) |
| 76 |
socket$listener |
| 77 |
close(socket$listener[[1]]) |
| 78 |
close(socket) |
| 79 |
|
| 80 |
nano <- nano("bus") |
| 81 |
nano$listen(url = "inproc://nanolisten", autostart = FALSE) |
| 82 |
nano$listener |
| 83 |
nano$listener_start() |
| 84 |
nano$listener |
| 85 |
close(nano$listener[[1]]) |
| 86 |
nano$close() |
| 87 |
|
| 88 |
} |