Learn R Programming

nanonext (version 0.5.1)

unsubscribe: Unsubscribe Topic

Description

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

Usage

unsubscribe(con, topic = NULL)

# S3 method for nanoSocket unsubscribe(con, topic = NULL)

# S3 method for nanoContext unsubscribe(con, topic = NULL)

Arguments

con

a Socket or Context using the 'sub' protocol.

topic

[default NULL] an atomic type or NULL. The default NULL unsubscribes from all topics (if all topics were previously subscribed).

Value

Invisibly, an integer exit code (zero 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.

  • ensure the sent vector starts with the topic.

The subscriber should then receive specifying the correct mode.

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")
send(pub, "examples will also be received", mode = "raw")
recv(sub, "character")
unsubscribe(sub, NULL)
send(pub, c("examples", "this example will not be received"), mode = "raw")
recv(sub, "character")

subscribe(sub, 2)
send(pub, c(2, 10, 10, 20), mode = "raw")
recv(sub, "double", keep.raw = FALSE)

close(pub)
close(sub)

# }

Run the code above in your browser using DataLab