## Not run:
# ### 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, .pbd_env$ZMQ.ST$REP)
# zmq.bind(responder, "tcp://*:5555")
#
# ret <- zmq.recv.multipart(responder, unserialize = TRUE)
# parts <- as.list(rep("World", 5))
# zmq.send.multipart(responder, parts)
# for(i in 1:5) cat(ret[[i]])
#
# 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, .pbd_env$ZMQ.ST$REQ)
# zmq.connect(requester, "tcp://localhost:5555")
#
# parts <- lapply(1:5, function(i.req){ paste("Sending Hello ", i.req, "\n") })
# zmq.send.multipart(requester, parts)
# ret <- zmq.recv.multipart(requester, unserialize = TRUE)
# print(ret)
#
# zmq.close(requester)
# zmq.ctx.destroy(context)
# ## End(Not run)
Run the code above in your browser using DataCamp Workspace