Message functions
an R message
a ZMQ socket
a flag for method of send and receive
if serialize the rmsg
NULL or numeric; the workspace format version to use when serializing. NULL specifies the current default version. The only other supported values are 2 and 3
if unserialize the received R message
zmq.msg.send() returns 0 if successful, otherwise returns -1
and sets errno to EFAULT.
zmq.msg.recv() returns the message if successful, otherwise returns
-1 and sets errno to EFAULT.
zmq.msg.send() sends an R message.
zmq.msg.recv() receives an R message.
ZeroMQ/4.1.0 API Reference: https://libzmq.readthedocs.io/en/zeromq4-1/
Programming with Big Data in R Website: https://pbdr.org/
if (FALSE) { # \dontrun{
### Using request-reply pattern.
### At the server, run next in background or the other window.
library(pbdZMQ, quietly = TRUE)
context <- zmq.ctx.new()
responder <- zmq.socket(context, ZMQ.ST()$REP)
zmq.bind(responder, "tcp://*:5555")
buf <- zmq.msg.recv(responder)
set.seed(1234)
ret <- rnorm(5)
print(ret)
zmq.msg.send(ret, responder)
zmq.close(responder)
zmq.ctx.destroy(context)
### At a client, run next in foreground.
library(pbdZMQ, quietly = TRUE)
context <- zmq.ctx.new()
requester <- zmq.socket(context, ZMQ.ST()$REQ)
zmq.connect(requester, "tcp://localhost:5555")
zmq.msg.send(NULL, requester)
ret <- zmq.msg.recv(requester)
print(ret)
zmq.close(requester)
zmq.ctx.destroy(context)
} # }