Learn R Programming

nanonext (version 0.1.0)

unsubscribe: Unsubscribe Topic

Description

For a socket using the sub protocol in a publisher/subscriber pattern. Remove a topic from the subscription list.

Usage

unsubscribe(socket, topic = NULL)

Arguments

socket

a Socket.

topic

[default NULL] a topic (given as a character string). The default NULL unsubscribes from all topics (if all topics were previously subscribed).

Value

Zero (invisibly) on success.

Details

Note that if the topic was not previously subscribed to then an 'entry not found' error will result.

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, NULL)
send_vec(pub, c("examples", "this is an example"))
recv_vec(sub, "character")
unsubscribe(sub, NULL)
send_vec(pub, c("examples", "this example will not be received"))
recv_vec(sub, "character")

close(pub)
close(sub)

# }

Run the code above in your browser using DataLab