Learn R Programming

nanonext (version 0.2.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 using the sub protocol.

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 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.

Examples

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

subscribe(sub, NULL)
send(pub, c("examples", "this is an example"), mode = "raw")
recv(sub, "character")
unsubscribe(sub, NULL)
send(pub, c("examples", "this example will not be received"), mode = "raw")
recv(sub, "character")

close(pub)
close(sub)

# }

Run the code above in your browser using DataLab