| 1 | if (interactive()) |
| 2 | cat("WARNING: You are encouraged to run the server in batch; you can do so by executing 'Rscript server.r' from a terminal.\n\n") |
| 3 | |
| 4 | library(pbdZMQ) |
| 5 | ctxt <- zmq.ctx.new() |
| 6 | socket <- zmq.socket(ctxt, ZMQ.ST()$REP) |
| 7 | zmq.bind(socket, "tcp://*:55555") |
| 8 | |
| 9 | |
| 10 | while(TRUE) |
| 11 | { |
| 12 | cat("Client command: ") |
| 13 | msg <- zmq.msg.recv(socket) |
| 14 | cat(msg, "\n") |
| 15 | |
| 16 | if (msg == "EXIT") |
| 17 | break |
| 18 | |
| 19 | result <- eval(parse(text=msg)) |
| 20 | |
| 21 | zmq.msg.send(result, socket) |
| 22 | } |
| 23 | |
| 24 | zmq.msg.send("shutting down!", socket) |
| 25 | |
| 26 | zmq.close(socket) |
| 27 | zmq.ctx.destroy(ctxt) |