Learn R Programming

nanonext (version 0.2.0)

context: Open Context

Description

Open a new Context to be used with a Socket. The purpose of a Context is to permit applications to share a single socket, with its underlying dialers and listeners, while still benefiting from separate state tracking.

Usage

context(socket)

Arguments

socket

a Socket or nano object.

Value

A new Context (object of class 'nanoContext' and 'nano').

Details

For convenience, this function may be called on a nano object as well as a socket, in which case it is the equivalent of calling the function on the object's socket directly.

Contexts allow the independent and concurrent use of stateful operations using the same socket. For example, two different contexts created on a rep socket can each receive requests, and send replies to them, without any regard to or interference with each other.

Note: not every protocol supports creation of separate contexts.

To send and receive over a context use send_ctx and recv_ctx respectively. It is also possible to perform async send and receive over a context using send_aio and recv_aio.

Examples

Run this code
# NOT RUN {
s <- socket("req", listen = "inproc://nanonext")
ctx <- context(s)
ctx
close(ctx)
close(s)

n <- nano("req", listen = "inproc://nanonext")
ctx <- context(n)
ctx
close(ctx)
n$close()

# }

Run the code above in your browser using DataLab