Rserve方式连接别的服务器

Rserve

Rserve的方式,这是一个基于TCP/IP的服务器,通过二进制协议传输数据,可以提供远程连接,使得客户端语言能够调用R

既然是TCP/IP 就可以在不同的机器上运行了

事实上官网给出了这么一句话

If no config file is supplied, Rserve accepts no remote connections
说明了如果不配置是不支持 远程链接的
如果你在代码里指定IP的话,是会链接失败的。不管是你自己的IP还是别人的。
 
package com.rTest;

import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {

        try {
            RConnection rc = new RConnection("192.168.1.152",6311);
            
            REXP x = rc.eval("R.version.string");
            System.err.println(x.asString());
            
            
            x = rc.eval("a <- 100");
            System.out.println(x.asString());
            
                       
        } catch (RserveException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (REXPMismatchException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
启动的时候可以直接用参数让远程连接开启
> library(Rserve)
> Rserve(args="--RS-enable-remote")

 也可以使用配置文件的方式,这种方式我没测试

原文地址:https://www.cnblogs.com/tomcattd/p/3371544.html