Debian Codegraph @

man/a1_socket.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/R_zmq_socket.r
3 \name{Socket Functions}
4 \alias{Socket Functions}
5 \alias{zmq.socket}
6 \alias{zmq.close}
7 \alias{zmq.bind}
8 \alias{zmq.connect}
9 \alias{zmq.disconnect}
10 \alias{zmq.setsockopt}
11 \alias{zmq.getsockopt}
12 \title{Socket Functions}
13 \usage{
14 zmq.socket(ctx, type = ZMQ.ST()$REP)
15
16 zmq.close(socket)
17
18 zmq.bind(socket, endpoint, MC = ZMQ.MC())
19
20 zmq.connect(socket, endpoint, MC = ZMQ.MC())
21
22 zmq.disconnect(socket, endpoint, MC = ZMQ.MC())
23
24 zmq.setsockopt(socket, option.name, option.value, MC = ZMQ.MC())
25
26 zmq.getsockopt(socket, option.name, option.value, MC = ZMQ.MC())
27 }
28 \arguments{
29 \item{ctx}{a ZMQ context}
30
31 \item{type}{a socket type}
32
33 \item{socket}{a ZMQ socket}
34
35 \item{endpoint}{a ZMQ socket endpoint}
36
37 \item{MC}{a message control, see \code{\link{ZMQ.MC}()} for details}
38
39 \item{option.name}{an option name to the socket}
40
41 \item{option.value}{an option value to the option name}
42 }
43 \value{
44 \code{zmq.socket()} returns an R external pointer (\code{socket})
45 generated by ZMQ C API pointing to a socket if successful, otherwise returns
46 an R \code{NULL} and sets \code{errno} to the error value, see ZeroMQ manual
47 for details.
48
49 \code{zmq.close()} destroys the socket reference/pointer (\code{socket}) and
50 returns 0 if successful, otherwise returns -1 and sets \code{errno} to the
51 error value, see ZeroMQ manual for details.
52
53 \code{zmq.bind()} binds the socket to specific \code{endpoint} and returns 0
54 if successful, otherwise returns -1 and sets \code{errno} to the error
55 value, see ZeroMQ manual for details.
56
57 \code{zmq.connect()} connects the socket to specific \code{endpoint} and
58 returns 0 if successful, otherwise returns -1 and sets \code{errno} to the
59 error value, see ZeroMQ manual for details.
60
61 \code{zmq.setsockopt()} sets/changes the socket option and returns 0 if
62 successful, otherwise returns -1 and sets \code{errno} to the error value,
63 see ZeroMQ manual for details.
64
65 \code{zmq.getsockopt()} returns the value of socket option,
66 see ZeroMQ manual for details.
67 }
68 \description{
69 Socket functions
70 }
71 \details{
72 \code{zmq.socket()} initials a ZMQ socket given a ZMQ context \code{ctx} and
73 a socket \code{type}. See \code{\link{ZMQ.ST}()} for the possible values of
74 \code{type}. ZMQ defines several patterns for the socket type and utilize
75 them to communicate in different ways including request-reply,
76 publish-subscribe, pipeline, exclusive pair, and naive patterns.
77
78 \code{zmq.close()} destroys the ZMQ socket.
79
80 \code{zmq.bind()} binds the socket to a local endpoint and then accepts
81 incoming connections on that endpoint. See \code{endpoint} next for details.
82
83 \code{zmq.connect()} connects the socket to a remote endpoint and then
84 accepts outgoing connections on that endpoint. See \code{endpoint} next for
85 details.
86
87 \code{endpoint} is a string consisting of a transport :// followed by an
88 address. The transport specifies the underlying protocol to use. The address
89 specifies the transport-specific address to bind to. pbdZMQ/ZMQ provides
90 the following transports: \tabular{ll}{ Transport \tab Usage \cr \code{tcp}
91 \tab unicast transport using TCP \cr \code{ipc} \tab local inter-process
92 communication transport \cr \code{inproc} \tab local in-process
93 (inter-thread) communication transport \cr \code{pgm,epgm} \tab reliable
94 multicast transport using PGM } *** warning: \code{epgm} is not turned on by
95 default in the pbdZMQ's internal ZeroMQ library. \cr *** warning: \code{ipc}
96 is not supported in Windows system.
97
98 \code{zmq.setsockopt()} is to set/change socket options.
99
100 \code{zmq.getsockopt()} is to get socket options and returns
101 \code{option.value}.
102 }
103 \examples{
104 \dontrun{
105 ### Using request-reply pattern.
106
107 ### At the server, run next in background or the other windows.
108 library(pbdZMQ, quietly = TRUE)
109
110 context <- zmq.ctx.new()
111 responder <- zmq.socket(context, ZMQ.ST()$REP)
112 zmq.bind(responder, "tcp://*:5555")
113 zmq.close(responder)
114 zmq.ctx.destroy(context)
115
116
117 ### At a client, run next in foreground.
118 library(pbdZMQ, quietly = TRUE)
119
120 context <- zmq.ctx.new()
121 requester <- zmq.socket(context, ZMQ.ST()$REQ)
122 zmq.connect(requester, "tcp://localhost:5555")
123 zmq.close(requester)
124 zmq.ctx.destroy(context)
125 }
126
127 }
128 \references{
129 ZeroMQ/4.1.0 API Reference:
130 \url{https://libzmq.readthedocs.io/en/zeromq4-1/}
131
132 Programming with Big Data in R Website: \url{https://pbdr.org/}
133 }
134 \seealso{
135 \code{\link{zmq.ctx.new}()}, \code{\link{zmq.ctx.destroy}()}.
136 }
137 \author{
138 Wei-Chen Chen \email{[email protected]}.
139 }
140 \keyword{programming}