| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/stream.R |
| 3 |
\name{stream} |
| 4 |
\alias{stream} |
| 5 |
\title{Open Stream} |
| 6 |
\usage{ |
| 7 |
stream( |
| 8 |
dial = NULL, |
| 9 |
listen = NULL, |
| 10 |
textframes = FALSE, |
| 11 |
headers = NULL, |
| 12 |
tls = NULL, |
| 13 |
buffer = 65536L |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{dial}{a URL to dial, specifying the transport and address as a |
| 18 |
character string e.g. 'ipc:///tmp/anyvalue' or 'tcp://127.0.0.1:5555' (not |
| 19 |
all transports are supported).} |
| 20 |
|
| 21 |
\item{listen}{a URL to listen at, specifying the transport and address as a |
| 22 |
character string e.g. 'ipc:///tmp/anyvalue' or 'tcp://127.0.0.1:5555' (not |
| 23 |
all transports are supported).} |
| 24 |
|
| 25 |
\item{textframes}{[default FALSE] applicable to the websocket transport |
| 26 |
only, enables sending and receiving of TEXT frames (ignored otherwise).} |
| 27 |
|
| 28 |
\item{headers}{(optional) applicable to websocket connections only, a |
| 29 |
\strong{named} character vector specifying custom request headers to send during |
| 30 |
the WebSocket upgrade handshake e.g. |
| 31 |
\code{c(Authorization = "Bearer token", Custom = "value")} (ignored for |
| 32 |
non-websocket transports).} |
| 33 |
|
| 34 |
\item{tls}{(optional) applicable to secure websockets only, a client or |
| 35 |
server TLS configuration object created by \code{\link[=tls_config]{tls_config()}}. If missing or |
| 36 |
NULL, certificates are not validated.} |
| 37 |
|
| 38 |
\item{buffer}{[default 65536L] applicable to non-websocket streams only, the |
| 39 |
maximum number of bytes to receive. Can be an over-estimate, but note that |
| 40 |
a buffer of this size is reserved. Not used for websocket connections, |
| 41 |
which handle framing automatically.} |
| 42 |
} |
| 43 |
\value{ |
| 44 |
A Stream (object of class 'nanoStream' and 'nano'). |
| 45 |
} |
| 46 |
\description{ |
| 47 |
Open a Stream by either dialing (establishing an outgoing connection) or |
| 48 |
listening (accepting an incoming connection) at an address. This is a |
| 49 |
low-level interface intended for communicating with non-NNG endpoints. |
| 50 |
} |
| 51 |
\details{ |
| 52 |
A Stream is used for raw byte stream connections. Byte streams are reliable |
| 53 |
in that data will not be delivered out of order, or with portions missing. |
| 54 |
|
| 55 |
Can be used to dial a (secure) websocket address starting 'ws://' or |
| 56 |
'wss://'. It is often the case that \code{textframes} needs to be set to \code{TRUE}. |
| 57 |
|
| 58 |
Specify only one of \code{dial} or \code{listen}. If both are specified, \code{listen} will |
| 59 |
be ignored. |
| 60 |
|
| 61 |
Closing a stream renders it invalid and attempting to perform additional |
| 62 |
operations on it will error. |
| 63 |
} |
| 64 |
\examples{ |
| 65 |
# Will succeed only if there is an open connection at the address: |
| 66 |
s <- tryCatch(stream(dial = "tcp://127.0.0.1:5555"), error = identity) |
| 67 |
s |
| 68 |
\dontshow{if (interactive()) withAutoprint(\{ # examplesIf} |
| 69 |
# Run in interactive sessions only as connection is not always available: |
| 70 |
s <- tryCatch( |
| 71 |
stream(dial = "wss://echo.websocket.events/", textframes = TRUE), |
| 72 |
error = identity |
| 73 |
) |
| 74 |
s |
| 75 |
if (is_nano(s)) recv(s) |
| 76 |
if (is_nano(s)) send(s, "hello") |
| 77 |
if (is_nano(s)) recv(s) |
| 78 |
if (is_nano(s)) close(s) |
| 79 |
\dontshow{\}) # examplesIf} |
| 80 |
} |