Learn R Programming

nanonext (version 0.1.0)

subscribe: Subscribe Topic

Description

For a socket using the sub protocol in a publisher/subscriber pattern. Set a topic to subscribe to.

Usage

subscribe(socket, topic = NULL)

Arguments

socket

a Socket.

topic

[default NULL] a topic (given as a character string). The default NULL subscribes to all topics.

Value

Zero (invisibly) on success.

Details

To use pub/sub you must use send_vec and recv_vec so that the messages are not serialised otherwise the topics will not be recognised.

Note: the publisher needs to send a vector that separates the topic from the rest of the message such as send_vec(socket, c("topic", "message")) (this ensures that topic ends with the required null byte for it to be recognised).

Examples

Run this code
# NOT RUN {
pub <- socket("pub", listen = "inproc://nanonext")
sub <- socket("sub", dial = "inproc://nanonext")

subscribe(sub, "examples")
send_vec(pub, c("examples", "this is an example"))
recv_vec(sub, "character")
send_vec(pub, c("other", "this other topic will not be received"))
recv_vec(sub, "character")

close(pub)
close(sub)

# }

Run the code above in your browser using DataLab