| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/R_zmq_sendrecv_multipart.r |
| 3 |
\name{Send Receive Multiple Raw Buffers} |
| 4 |
\alias{Send Receive Multiple Raw Buffers} |
| 5 |
\alias{zmq.send.multipart} |
| 6 |
\alias{zmq.recv.multipart} |
| 7 |
\title{Send Receive Multiple Raw Buffers} |
| 8 |
\usage{ |
| 9 |
zmq.send.multipart(socket, parts, serialize = TRUE) |
| 10 |
|
| 11 |
zmq.recv.multipart(socket, unserialize = TRUE) |
| 12 |
} |
| 13 |
\arguments{ |
| 14 |
\item{socket}{a ZMQ socket} |
| 15 |
|
| 16 |
\item{parts}{a vector of multiple buffers to be sent} |
| 17 |
|
| 18 |
\item{serialize, unserialize}{if serialize/unserialize the received multiple buffers} |
| 19 |
} |
| 20 |
\value{ |
| 21 |
\code{zmq.send.multipart()} returns. |
| 22 |
|
| 23 |
\code{zmq.recv.multipart()} returns. |
| 24 |
} |
| 25 |
\description{ |
| 26 |
Send and receive functions for multiple raw buffers |
| 27 |
} |
| 28 |
\details{ |
| 29 |
\code{zmq.send.multipart()} is a high level R function to send multiple |
| 30 |
raw messages \code{parts} at once. |
| 31 |
|
| 32 |
\code{zmq.recv.multipart()} is a high level R function to receive multiple |
| 33 |
raw messages at once. |
| 34 |
} |
| 35 |
\examples{ |
| 36 |
\dontrun{ |
| 37 |
### Using request-reply pattern. |
| 38 |
|
| 39 |
### At the server, run next in background or the other window. |
| 40 |
library(pbdZMQ, quietly = TRUE) |
| 41 |
|
| 42 |
context <- zmq.ctx.new() |
| 43 |
responder <- zmq.socket(context, ZMQ.ST()$REP) |
| 44 |
zmq.bind(responder, "tcp://*:5555") |
| 45 |
|
| 46 |
ret <- zmq.recv.multipart(responder, unserialize = TRUE) |
| 47 |
parts <- as.list(rep("World", 5)) |
| 48 |
zmq.send.multipart(responder, parts) |
| 49 |
for(i in 1:5) cat(ret[[i]]) |
| 50 |
|
| 51 |
zmq.close(responder) |
| 52 |
zmq.ctx.destroy(context) |
| 53 |
|
| 54 |
### At a client, run next in foreground. |
| 55 |
library(pbdZMQ, quietly = TRUE) |
| 56 |
|
| 57 |
context <- zmq.ctx.new() |
| 58 |
requester <- zmq.socket(context, ZMQ.ST()$REQ) |
| 59 |
zmq.connect(requester, "tcp://localhost:5555") |
| 60 |
|
| 61 |
parts <- lapply(1:5, function(i.req){ paste("Sending Hello ", i.req, "\n") }) |
| 62 |
zmq.send.multipart(requester, parts) |
| 63 |
ret <- zmq.recv.multipart(requester, unserialize = TRUE) |
| 64 |
print(ret) |
| 65 |
|
| 66 |
zmq.close(requester) |
| 67 |
zmq.ctx.destroy(context) |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
\references{ |
| 72 |
ZeroMQ/4.1.0 API Reference: |
| 73 |
\url{https://libzmq.readthedocs.io/en/zeromq4-1/} |
| 74 |
|
| 75 |
Programming with Big Data in R Website: \url{https://pbdr.org/} |
| 76 |
} |
| 77 |
\seealso{ |
| 78 |
\code{\link{zmq.msg.send}()}, \code{\link{zmq.msg.recv}()}. |
| 79 |
} |
| 80 |
\author{ |
| 81 |
Wei-Chen Chen \email{[email protected]}. |
| 82 |
} |
| 83 |
\keyword{programming} |