For a socket using the sub protocol in a publisher/subscriber pattern. Set a topic to subscribe to.
subscribe(socket, topic = NULL)
a Socket using the sub protocol.
[default NULL] a topic (given as a character string). The default NULL subscribes to all topics.
Zero (invisibly) on success.
To use pub/sub the publisher must:
specify mode = 'raw'
when sending to allow the topics to be
recognised by the receiving party.
send a vector that separates the topic from the rest of the message
e.g. send(socket, c("topic", "message"), mode = "raw")
- this
ensures that topic ends with the required null byte for it to be
recognised.
# NOT RUN {
pub <- socket("pub", listen = "inproc://nanonext")
sub <- socket("sub", dial = "inproc://nanonext")
subscribe(sub, "examples")
send(pub, c("examples", "this is an example"), mode = "raw")
recv(sub, "character")
send(pub, c("other", "this other topic will not be received"), mode = "raw")
recv(sub, "character")
close(pub)
close(sub)
# }
Run the code above in your browser using DataLab