ropensci / rzmq

R package for ZMQ
https://docs.ropensci.org/rzmq
84 stars 30 forks source link

rzmq Client error with Python Server #53

Open chintanp opened 4 years ago

chintanp commented 4 years ago

I am trying to run the Request-reply example with a Python server and rzmq client.

The Python code I use is as in the zmq docs: http://zguide.zeromq.org/py:hwserver

The R code I am using is as in the docs, modified to send "Hello"

#!/usr/bin/env Rscript
library(rzmq)

remote.exec <- function(socket, fun, ...) {
  send.socket(socket, data = list(fun = fun, args = list(...)))
  receive.socket(socket)
}

substitute(expr)
context = init.context()
socket = init.socket(context, "ZMQ_REQ")
connect.socket(socket, "tcp://localhost:5555")

send.socket(socket, "Hello")
receive.socket(socket)

I see the server printing this:

Received request: b'B\n\x03\x00\x00\x00\x03\x06\x03\x00\x00\x05\x03\x00\x06\x00\x00\x00CP1252\x10\x00\x00\x00\x01\x00\x00\x00\t\x00\x04\x00\x05\x00\x00\x00Hello'

instead it should be:

Received request: b'Hello'

I tried running the R code as Rscript from command line, as well as from RStudio with same result. The client side (R) errors with following message:

expr
Error in unserialize(ans) : unknown input format
Calls: receive.socket -> unserialize
Execution halted

Any steps to debug this would be helpful. I am on Windows 10. I am running the Python server from WSL and the R code from RStudio and RStudio terminal. R version 3.6.3.