R Under development (unstable) (2024-09-15 r87152 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > suppressPackageStartupMessages(library(pbdZMQ)) > > ### zmq interface > > ### In general and separate files > # server_context = zmq.ctx.new() > # server_socket = zmq.socket(server_context, ZMQ.ST()$REP) > # client_context = zmq.ctx.new() > # client_socket = zmq.socket(client_context, ZMQ.ST()$REQ) > ### Server file > # zmq.setsockopt(server_socket, ZMQ.SO()$CONNECT_TIMEOUT, 1000L) > # zmq.setsockopt(server_socket, ZMQ.SO()$RCVTIMEO, 1000L) > # zmq.setsockopt(server_socket, ZMQ.SO()$SNDTIMEO, 1000L) > # zmq.bind(server_socket, "tcp://*:55555") > ### client file > # zmq.setsockopt(client_socket, ZMQ.SO()$CONNECT_TIMEOUT, 1000L) > # zmq.setsockopt(client_socket, ZMQ.SO()$RCVTIMEO, 1000L) > # zmq.setsockopt(client_socket, ZMQ.SO()$SNDTIMEO, 1000L) > # zmq.connect(client_socket, "tcp://localhost:55555") > > ### For CRAN testing in local (the same process) only to avoid block > cran_context = zmq.ctx.new() > server_socket = zmq.socket(cran_context, ZMQ.ST()$REP) > client_socket = zmq.socket(cran_context, ZMQ.ST()$REQ) > ### Server > zmq.bind(server_socket, "inproc://#1") > ### client > zmq.connect(client_socket, "inproc://#1") > > > ### Test pbdZMQ > tester = function(indata) + { + zmq.msg.send(indata, client_socket) + c2s <- zmq.msg.recv(server_socket) + stopifnot(all.equal(c2s, indata)) + + zmq.send(server_socket, "ok") + s2c <- zmq.recv(client_socket) + stopifnot(all.equal(s2c$buf, "ok")) + } > > tester("test") > tester(1:5) > > zmq.close(server_socket) > zmq.close(client_socket) > > proc.time() user system elapsed 0.21 0.07 0.28