Shashank gaur
Shashank gaur

Reputation: 55

Rserve Exception: Handshake failed

I am new to language R and was trying a simple program in java using RConnection but it is giving this exception

org.rosuda.REngine.Rserve.RserveException: Handshake failed: expected 32 bytes header, got -1
    at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:107)
    at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:60)
    at org.rosuda.REngine.Rserve.RConnection.<init>(RConnection.java:44)
    at test.sandeep.main(sandeep.java:9)

thats in the contuctor of RConnection. Can anyone tell what might be wrong package test;

import org.rosuda.REngine.Rserve.RConnection;

public class sandeep {
public static void main(String[] str) {

    try {
        System.out.println("hii");
        RConnection c = new RConnection();
        System.out.println("hii");
        double d[] = c.eval("rnorm(10)").asDoubles();
        for (double td : d) {
            System.out.println(td);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

}

Upvotes: 2

Views: 2986

Answers (2)

Krishna Rangaiah. K
Krishna Rangaiah. K

Reputation: 26

If you are running RServe on a linux box, make sure that you have the configuration file in /etc/ location with name "Rserv.conf" and with contents

remote enable

This enables remote access to RServe

Upvotes: 0

Simon Urbanek
Simon Urbanek

Reputation: 13932

The error says that read has failed immediately after connecting to Rserve. Your Java code is fine (assumint you are connecting to a local instance of Rserve). The issue is likely on the other side -- check that Rserve is running (see Rserve FAQ). You can also start Rserve in debug mode (Rserve(TRUE) in R) to see what happens on the server side.

Upvotes: 3

Related Questions