For a socket or context using the sub protocol in a publisher/subscriber pattern. Remove a topic from the subscription list.
unsubscribe(con, topic = NULL)
a Socket or Context using the 'sub' protocol.
[default NULL] an atomic type or NULL. The default NULL unsubscribes from all topics (if all topics were previously subscribed).
Invisibly, an integer exit code (zero on success).
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.
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")
#> [1] 0
recv(sub, "character")
#> [1] "examples" "this is an example"
unsubscribe(sub, "examples")
send(pub, c("examples", "this example will not be received"), mode = "raw")
#> [1] 0
recv(sub, "character")
#> 'errorValue' int 8 | Try again
subscribe(sub, 2)
send(pub, c(2, 10, 10, 20), mode = "raw")
#> [1] 0
recv(sub, "double", keep.raw = FALSE)
#> [1] 2 10 10 20
unsubscribe(sub, 2)
send(pub, c(2, 10, 10, 20), mode = "raw")
#> [1] 0
recv(sub, "double", keep.raw = FALSE)
#> 'errorValue' int 8 | Try again
close(pub)
close(sub)