Last chance! 50% off unlimited learning
Sale ends in
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)# S3 method for nanoSocket
unsubscribe(con, topic = NULL)
# S3 method for nanoContext
unsubscribe(con, topic = NULL)
Invisibly, an integer exit code (zero on success).
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).
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, 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