% Generated by roxygen2: do not edit by hand % Please edit documentation in R/context.R \name{context} \alias{context} \title{Open Context} \usage{ context(socket) } \arguments{ \item{socket}{a Socket.} } \value{ A Context (object of class 'nanoContext' and 'nano'). } \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. } \details{ 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. Only the following protocols support creation of contexts: req, rep, sub (in a pub/sub pattern), surveyor, respondent. To send and receive over a context use \code{\link[=send]{send()}} and \code{\link[=recv]{recv()}} or their async counterparts \code{\link[=send_aio]{send_aio()}} and \code{\link[=recv_aio]{recv_aio()}}. For nano objects, use the \verb{$context_open()} method, which will attach a new context at \verb{$context}. See \code{\link[=nano]{nano()}}. } \examples{ s <- socket("req", listen = "inproc://nanonext") ctx <- context(s) ctx close(ctx) close(s) n <- nano("req", listen = "inproc://nanonext") n$context_open() n$context n$context_open() n$context n$context_close() n$close() } \seealso{ \code{\link[=request]{request()}} and \code{\link[=reply]{reply()}} for use with contexts. }