File: send_recv_rzmq.R

package info (click to toggle)
r-cran-pbdzmq 0.3.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 856 kB
  • sloc: ansic: 737; sh: 93; pascal: 30; cpp: 6; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
suppressPackageStartupMessages(library(pbdZMQ))

### rzmq interface

### In general and separate files
# server_context = init.context()
# server_socket = init.socket(server_context, "ZMQ_REP")
# client_context = init.context()
# client_socket = init.socket(client_context, "ZMQ_REQ")
### Server file
# bind.socket(server_socket, "tcp://*:55555")
### Client file
# connect.socket(client_socket, "tcp://localhost:55555")

### For CRAN testing in local (the same process) only to avoid block
cran_context = init.context()
server_socket = init.socket(cran_context, "ZMQ_REP")
client_socket = init.socket(cran_context, "ZMQ_REQ")
### Server
bind.socket(server_socket, "inproc://#1")
### Client
connect.socket(client_socket, "inproc://#1")


### Test rzmq
tester_rzmq = function(indata)
{
  send.socket(client_socket, indata)
  c2s <- receive.socket(server_socket)
  stopifnot(all.equal(c2s, indata))

  send.socket(server_socket, "ok")
  s2c <- receive.socket(client_socket)
  stopifnot(all.equal(s2c, "ok"))
}

tester_rzmq("test")
tester_rzmq(1:5)