| 1 | ### Hello world client as in the ZeroMQ guide. |
| 2 | # SHELL> Rscript hwserver.r & |
| 3 | # SHELL> Rscript hwclient.r |
| 4 | |
| 5 | suppressMessages(library(pbdZMQ, quietly = TRUE)) |
| 6 | |
| 7 | ### Initial. |
| 8 | context <- zmq.ctx.new() |
| 9 | requester <- zmq.socket(context, ZMQ.ST()$REQ) |
| 10 | zmq.connect(requester, "tcp://localhost:5555") |
| 11 | |
| 12 | ### Send and receive 5 times. |
| 13 | for(i.req in 1:5){ |
| 14 | cat("Sending Hello ", i.req, "\n") |
| 15 | zmq.send(requester, "Hello") |
| 16 | buf <- zmq.recv(requester, 10L) |
| 17 | cat("Received World ", i.req, "\n") |
| 18 | } |
| 19 | |
| 20 | ### Finish. |
| 21 | zmq.close(requester) |
| 22 | zmq.ctx.destroy(context) |