| 1 | ### Iterative pollers |
| 2 | # SHELL> Rscript iter_try.r |
| 3 | |
| 4 | suppressMessages(library(pbdZMQ, quietly = TRUE)) |
| 5 | |
| 6 | ### Initial. |
| 7 | context <- zmq.ctx.new() |
| 8 | receiver <- zmq.socket(context, ZMQ.ST()$PULL) |
| 9 | zmq.connect(receiver, "tcp://localhost:5557") |
| 10 | |
| 11 | ### Process messages from the socket. |
| 12 | for(i in 1:5){ |
| 13 | cat("Press Ctrl+C or Esc to stop iter_script ... ", i, "\n", sep = "") |
| 14 | aa <- tryCatch(zmq.poll(c(receiver), c(ZMQ.PO()$POLLIN)), |
| 15 | interrupt = function(c){ c$ret$pollret }) |
| 16 | print(aa) |
| 17 | } |
| 18 | |
| 19 | ### Finish. |
| 20 | zmq.close(receiver) |
| 21 | zmq.ctx.destroy(context) |