title: Error during cross platform communication between Node.js and R using Rserve on AWS. Error:connect ETIMEDOUT
body: <p>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.</p>
  
  <p>I found two reliable options:
  <br>
  1) <a href="https://www.npmjs.com/package/rio" rel="nofollow noreferrer">RIO</a> - (Used this)
  <br>
  2) <a href="https://www.npmjs.com/package/rserve-client" rel="nofollow noreferrer">rserve-client</a></p>
  
  <p>Before proceeding to connect with Rserve, I made sure it was initiated and running. </p>
  
  <pre><code>ubuntu@ip-172-31-37-254:~$ sudo netstat -nltp|grep Rserve
  tcp        0      0 0.0.0.0:6311            0.0.0.0:*               LISTEN 5978/Rserve
  </code></pre>
  
  <p>Enabled the remote connection parameter for Rserve and got it started successfully.</p>
  
  <pre><code>library(Rserve)
  Rserve(args="--RS-enable-remote")
  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.
  </code></pre>
  
  <p>1) Tried a test script using <a href="https://www.npmjs.com/package/rio" rel="nofollow noreferrer">RIO</a> package from my Node.js application</p>
  
  <pre><code>var rio = require("rio");
  console.log("Connecting..");
  
  rio.e({
  
      host : "ec2-52-40-113-159.us-west-2.compute.amazonaws.com",
      port : "6311",
      command: "pi / 2 * 2",
  
      callback: function (err, res) {
          if (!err) {
              console.log(res);
          } else {
              console.log("Rserve call failed. " + err);
          }
      }
  
      // path :"/usr/local/lib/R/site-library"
  
  });
  </code></pre>
  
  <p>Note: As stated <a href="https://stackoverflow.com/questions/26593143/rserve-connection-from-local-r-client-to-rserve-host-on-aws-server">here</a>, I have the host parameter updated accordingly.</p>
  
  <p><br>Error while running the app:</p>
  
  <pre><code>node app.js
  Connecting..
  Rserve call failed. Error: connect ETIMEDOUT 52.40.113.159:6311
  </code></pre>
  
  <p>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.</p>