| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/opts.R |
| 3 |
\name{subscribe} |
| 4 |
\alias{subscribe} |
| 5 |
\alias{unsubscribe} |
| 6 |
\title{Subscribe / Unsubscribe Topic} |
| 7 |
\usage{ |
| 8 |
subscribe(con, topic = NULL) |
| 9 |
|
| 10 |
unsubscribe(con, topic = NULL) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{con}{a Socket or Context using the 'sub' protocol.} |
| 14 |
|
| 15 |
\item{topic}{[default NULL] an atomic type or \code{NULL}. The default \code{NULL} |
| 16 |
subscribes to all topics / unsubscribes from all topics (if all topics were |
| 17 |
previously subscribed).} |
| 18 |
} |
| 19 |
\value{ |
| 20 |
Invisibly, the passed Socket or Context. |
| 21 |
} |
| 22 |
\description{ |
| 23 |
For a socket or context using the sub protocol in a publisher/subscriber |
| 24 |
pattern. Set a topic to subscribe to, or remove a topic from the subscription |
| 25 |
list. |
| 26 |
} |
| 27 |
\details{ |
| 28 |
To use pub/sub the publisher must: |
| 29 |
\itemize{ |
| 30 |
\item specify \code{mode = 'raw'} when sending. |
| 31 |
\item ensure the sent vector starts with the topic. |
| 32 |
} |
| 33 |
The subscriber should then receive specifying the correct mode. |
| 34 |
} |
| 35 |
\examples{ |
| 36 |
pub <- socket("pub", listen = "inproc://nanonext") |
| 37 |
sub <- socket("sub", dial = "inproc://nanonext") |
| 38 |
|
| 39 |
subscribe(sub, "examples") |
| 40 |
|
| 41 |
send(pub, c("examples", "this is an example"), mode = "raw") |
| 42 |
recv(sub, "character") |
| 43 |
send(pub, "examples will also be received", mode = "raw") |
| 44 |
recv(sub, "character") |
| 45 |
send(pub, c("other", "this other topic will not be received"), mode = "raw") |
| 46 |
recv(sub, "character") |
| 47 |
unsubscribe(sub, "examples") |
| 48 |
send(pub, c("examples", "this example is no longer received"), mode = "raw") |
| 49 |
recv(sub, "character") |
| 50 |
|
| 51 |
subscribe(sub, 2) |
| 52 |
send(pub, c(2, 10, 10, 20), mode = "raw") |
| 53 |
recv(sub, "double") |
| 54 |
unsubscribe(sub, 2) |
| 55 |
send(pub, c(2, 10, 10, 20), mode = "raw") |
| 56 |
recv(sub, "double") |
| 57 |
|
| 58 |
close(pub) |
| 59 |
close(sub) |
| 60 |
|
| 61 |
} |