File: a1_socket.Rd

package info (click to toggle)
r-cran-pbdzmq 0.3.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 856 kB
  • sloc: ansic: 737; sh: 93; pascal: 30; cpp: 6; makefile: 4
file content (140 lines) | stat: -rw-r--r-- 4,503 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R_zmq_socket.r
\name{Socket Functions}
\alias{Socket Functions}
\alias{zmq.socket}
\alias{zmq.close}
\alias{zmq.bind}
\alias{zmq.connect}
\alias{zmq.disconnect}
\alias{zmq.setsockopt}
\alias{zmq.getsockopt}
\title{Socket Functions}
\usage{
zmq.socket(ctx, type = ZMQ.ST()$REP)

zmq.close(socket)

zmq.bind(socket, endpoint, MC = ZMQ.MC())

zmq.connect(socket, endpoint, MC = ZMQ.MC())

zmq.disconnect(socket, endpoint, MC = ZMQ.MC())

zmq.setsockopt(socket, option.name, option.value, MC = ZMQ.MC())

zmq.getsockopt(socket, option.name, option.value, MC = ZMQ.MC())
}
\arguments{
\item{ctx}{a ZMQ context}

\item{type}{a socket type}

\item{socket}{a ZMQ socket}

\item{endpoint}{a ZMQ socket endpoint}

\item{MC}{a message control, see \code{\link{ZMQ.MC}()} for details}

\item{option.name}{an option name to the socket}

\item{option.value}{an option value to the option name}
}
\value{
\code{zmq.socket()} returns an R external pointer (\code{socket})
generated by ZMQ C API pointing to a socket if successful, otherwise returns
an R \code{NULL} and sets \code{errno} to the error value, see ZeroMQ manual
for details.

\code{zmq.close()} destroys the socket reference/pointer (\code{socket}) and
returns 0 if successful, otherwise returns -1 and sets \code{errno} to the
error value, see ZeroMQ manual for details.

\code{zmq.bind()} binds the socket to specific \code{endpoint} and returns 0
if successful, otherwise returns -1 and sets \code{errno} to the error
value, see ZeroMQ manual for details.

\code{zmq.connect()} connects the socket to specific \code{endpoint} and
returns 0 if successful, otherwise returns -1 and sets \code{errno} to the
error value, see ZeroMQ manual for details.

\code{zmq.setsockopt()} sets/changes the socket option and returns 0 if
successful, otherwise returns -1 and sets \code{errno} to the error value,
see ZeroMQ manual for details.

\code{zmq.getsockopt()} returns the value of socket option,
see ZeroMQ manual for details.
}
\description{
Socket functions
}
\details{
\code{zmq.socket()} initials a ZMQ socket given a ZMQ context \code{ctx} and
a socket \code{type}. See \code{\link{ZMQ.ST}()} for the possible values of
\code{type}. ZMQ defines several patterns for the socket type and utilize
them to communicate in different ways including request-reply,
publish-subscribe, pipeline, exclusive pair, and naive patterns.

\code{zmq.close()} destroys the ZMQ socket.

\code{zmq.bind()} binds the socket to a local endpoint and then accepts
incoming connections on that endpoint. See \code{endpoint} next for details.

\code{zmq.connect()} connects the socket to a remote endpoint and then
accepts outgoing connections on that endpoint. See \code{endpoint} next for
details.

\code{endpoint} is a string consisting of a transport :// followed by an
address. The transport specifies the underlying protocol to use. The address
specifies the transport-specific address to bind to.  pbdZMQ/ZMQ provides
the following transports: \tabular{ll}{ Transport \tab Usage \cr \code{tcp}
\tab unicast transport using TCP \cr \code{ipc} \tab local inter-process
communication transport \cr \code{inproc} \tab local in-process
(inter-thread) communication transport \cr \code{pgm,epgm} \tab reliable
multicast transport using PGM } *** warning: \code{epgm} is not turned on by
default in the pbdZMQ's internal ZeroMQ library. \cr *** warning: \code{ipc}
is not supported in Windows system.

\code{zmq.setsockopt()} is to set/change socket options.

\code{zmq.getsockopt()} is to get socket options and returns
\code{option.value}.
}
\examples{
\dontrun{
### Using request-reply pattern.

### At the server, run next in background or the other windows.
library(pbdZMQ, quietly = TRUE)

context <- zmq.ctx.new()
responder <- zmq.socket(context, ZMQ.ST()$REP)
zmq.bind(responder, "tcp://*:5555")
zmq.close(responder)
zmq.ctx.destroy(context)


### At a client, run next in foreground.
library(pbdZMQ, quietly = TRUE)

context <- zmq.ctx.new()
requester <- zmq.socket(context, ZMQ.ST()$REQ)
zmq.connect(requester, "tcp://localhost:5555")
zmq.close(requester)
zmq.ctx.destroy(context)
}

}
\references{
ZeroMQ/4.1.0 API Reference:
\url{https://libzmq.readthedocs.io/en/zeromq4-1/}

Programming with Big Data in R Website: \url{https://pbdr.org/}
}
\seealso{
\code{\link{zmq.ctx.new}()}, \code{\link{zmq.ctx.destroy}()}.
}
\author{
Wei-Chen Chen \email{wccsnow@gmail.com}.
}
\keyword{programming}