使用Rserve重置Java.net连接

时间:2016-08-31 09:59:38

标签: java r sockets exception rserve

尝试通过Java运行R程序时遇到异常。正在建立连接但是在R代码的评估开始时抛出了错误。

Rconnection connection = new RConnection();

System.out.println(String.valueOf(connection.isConnected())); //Output: True
connection.eval("source('C:\\Users\\Vini\\Documents\\test.R')"); //Exception in this line

我已经在Rserve中启动了R

java.net.SocketException: Connection reset
  at java.net.SocketInputStream.read(SocketInputStream.java:209)
  at java.net.SocketInputStream.read(SocketInputStream.java:141)
  at java.net.SocketInputStream.read(SocketInputStream.java:127)
  at org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:213)
  at org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:180)
  at org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:250)
  at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:231)
  at integration.Integration.main(Integration.java:36)
org.rosuda.REngine.Rserve.RserveException: eval failed
  at org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:234)
  at integration.Integration.main(Integration.java:36)

1 个答案:

答案 0 :(得分:0)

问题是isConnected无法保证在建立连接后它会报告正确的状态:

  

请注意,目前此状态未在现场检查,即如果连接因外部事件而中断,则不会被标记反映

您需要检查Rserve日志以检查该请求是否已成功处理