Nick_inaw Nick_inaw - 1 year ago 102
Node.js Question

Error during cross platform communication between Node.js and R using Rserve on AWS. Error:connect ETIMEDOUT

I want to pass my R script from my node.js application to an Amazon EC2 instance running Ubuntu and Rserve; which would then execute and evaluate the R script and return the processed output back to my node.js application.

I found two reliable options:

1) RIO - (Used this)

2) rserve-client

Before proceeding to connect with Rserve, I made sure it was initiated and running.

ubuntu@ip-172-31-37-254:~$ sudo netstat -nltp|grep Rserve
tcp 0 0* LISTEN 5978/Rserve

Enabled the remote connection parameter for Rserve and got it started successfully.

Starting Rserve:
/usr/lib/R/bin/R CMD /usr/local/lib/R/site-library/Rserve/libs//Rserve --RS-enable-remote

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

During startup - Warning message:
Setting LC_CTYPE failed, using "C"
Rserv started in daemon mode.

1) Tried a test script using RIO package from my Node.js application

var rio = require("rio");


host : "",
port : "6311",
command: "pi / 2 * 2",

callback: function (err, res) {
if (!err) {
} else {
console.log("Rserve call failed. " + err);

// path :"/usr/local/lib/R/site-library"


Note: As stated here, I have the host parameter updated accordingly.

Error while running the app:

node app.js
Rserve call failed. Error: connect ETIMEDOUT

I'm not sure, why is it that I am unable to connect. Is there any step that I am missing? Would also appreciate if there is any alternate package or way of accomplishing this task. Thanks.

Answer Source

The issue in your use case is proper ports not open in your Security groups.

You will have to open port 6311 and 5978 in the EC2 security group and the issue will go.

Instead of making port 6311 and 5878 open to world you can add below rules to EC2 security group.

Type: Custom TCP Rule, Protocol: TCP, Port Range: 6311, Source: Node.js Server IP
Type: Custom TCP Rule, Protocol: TCP, Port Range: 5978, Source: Node.js Server IP