Debian Codegraph @

man/socket.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/socket.R
3 \name{socket}
4 \alias{socket}
5 \title{Open Socket}
6 \usage{
7 socket(
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 raw = FALSE
15 )
16 }
17 \arguments{
18 \item{protocol}{[default 'bus'] choose protocol - \code{"bus"}, \code{"pair"},
19 \code{"poly"}, \code{"push"}, \code{"pull"}, \code{"pub"}, \code{"sub"}, \code{"req"}, \code{"rep"},
20 \code{"surveyor"}, or \code{"respondent"} - see \link{protocols}.}
21
22 \item{dial}{(optional) a URL to dial, specifying the transport and address as
23 a character string e.g. 'inproc://anyvalue' or 'tcp://127.0.0.1:5555' (see
24 \link{transports}).}
25
26 \item{listen}{(optional) a URL to listen at, specifying the transport and
27 address as a character string e.g. 'inproc://anyvalue' or
28 'tcp://127.0.0.1:5555' (see \link{transports}).}
29
30 \item{tls}{[default NULL] for secure tls+tcp:// or wss:// connections only,
31 provide a TLS configuration object created by \code{\link[=tls_config]{tls_config()}}.}
32
33 \item{autostart}{[default TRUE] whether to start the dialer/listener. Set
34 to FALSE if setting configuration options on the dialer/listener as it is
35 not generally possible to change these once started. For dialers only: set
36 to NA to start synchronously - this is less resilient if a connection is
37 not immediately possible, but avoids subtle errors from attempting to use
38 the socket before an asynchronous dial has completed.}
39
40 \item{raw}{[default FALSE] whether to open raw mode sockets. Note: not for
41 general use - do not enable unless you have a specific need (refer to NNG
42 documentation).}
43 }
44 \value{
45 A Socket (object of class 'nanoSocket' and 'nano').
46 }
47 \description{
48 Open a Socket implementing \code{protocol}, and optionally dial (establish an
49 outgoing connection) or listen (accept an incoming connection) at an address.
50 }
51 \details{
52 NNG presents a socket view of networking. The sockets are constructed using
53 protocol-specific functions, as a given socket implements precisely one
54 protocol.
55
56 Each socket may be used to send and receive messages (if the protocol
57 supports it, and implements the appropriate protocol semantics). For example,
58 sub sockets automatically filter incoming messages to discard those for
59 topics that have not been subscribed.
60
61 This function (optionally) binds a single Dialer and/or Listener to a Socket.
62 More complex network topologies may be created by binding further Dialers /
63 Listeners to the Socket as required using \code{\link[=dial]{dial()}} and \code{\link[=listen]{listen()}}.
64
65 New contexts may also be created using \code{\link[=context]{context()}} if the protocol supports
66 it.
67 }
68 \section{Protocols}{
69
70
71 The following Scalability Protocols (communication patterns) are implemented:
72 \itemize{
73 \item Bus (mesh networks) - protocol: 'bus'
74 \item Pair (two-way radio) - protocol: 'pair'
75 \item Poly (one-to-one of many) - protocol: 'poly'
76 \item Pipeline (one-way pipe) - protocol: 'push', 'pull'
77 \item Publisher/Subscriber (topics & broadcast) - protocol: 'pub', 'sub'
78 \item Request/Reply (RPC) - protocol: 'req', 'rep'
79 \item Survey (voting & service discovery) - protocol: 'surveyor',
80 'respondent'
81 }
82
83 Please see \link{protocols} for further documentation.
84 }
85
86 \section{Transports}{
87
88
89 The following communications transports may be used:
90
91 \itemize{
92 \item Inproc (in-process) - url: 'inproc://'
93 \item IPC (inter-process communications) - url: 'ipc://' (or 'abstract://'
94 on Linux)
95 \item TCP and TLS over TCP - url: 'tcp://' and 'tls+tcp://'
96 \item WebSocket and TLS over WebSocket - url: 'ws://' and 'wss://'
97 }
98
99 Please see \link{transports} for further documentation.
100 }
101
102 \examples{
103 s <- socket(protocol = "req", listen = "inproc://nanosocket")
104 s
105 s1 <- socket(protocol = "rep", dial = "inproc://nanosocket")
106 s1
107
108 send(s, "hello world!")
109 recv(s1)
110
111 close(s1)
112 close(s)
113
114 }