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)

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

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")
#>  [1] 65 78 61 6d 70 6c 65 73 00 74 68 69 73 20 69 73 20 61 6e 20 65 78 61 6d 70
#> [26] 6c 65 00
recv(sub, "character")
#> $raw #> [1] 65 78 61 6d 70 6c 65 73 00 74 68 69 73 20 69 73 20 61 6e 20 65 78 61 6d 70 #> [26] 6c 65 00 #> #>$data
#> [1] "examples"           "this is an example"
#>
send(pub, "examples will also be received", mode = "raw")
#>  [1] 65 78 61 6d 70 6c 65 73 20 77 69 6c 6c 20 61 6c 73 6f 20 62 65 20 72 65 63
#> [26] 65 69 76 65 64 00
recv(sub, "character")
#> $raw #> [1] 65 78 61 6d 70 6c 65 73 20 77 69 6c 6c 20 61 6c 73 6f 20 62 65 20 72 65 63 #> [26] 65 69 76 65 64 00 #> #>$data
#> [1] "examples will also be received"
#>
unsubscribe(sub, NULL)
send(pub, c("examples", "this example will not be received"), mode = "raw")
#>  [1] 65 78 61 6d 70 6c 65 73 00 74 68 69 73 20 65 78 61 6d 70 6c 65 20 77 69 6c
#> [26] 6c 20 6e 6f 74 20 62 65 20 72 65 63 65 69 76 65 64 00
recv(sub, "character")
#> Warning: 8 | Try again
#> 'errorValue' int 8

subscribe(sub, 2)
send(pub, c(2, 10, 10, 20), mode = "raw")
#>  [1] 00 00 00 00 00 00 00 40 00 00 00 00 00 00 24 40 00 00 00 00 00 00 24 40 00
#> [26] 00 00 00 00 00 34 40
recv(sub, "double", keep.raw = FALSE)
#> [1]  2 10 10 20

close(pub)
close(sub)