0

I'm pretty new to this...

I have the following code:

request("http://somePythonServer.com?param1=1&param2=2", function (err, response, body) {
      if (err){
         console.error(err);
         next(err);
      }
      console.log("Response Ended - SUCCESS");
});

This request is made each time with different parameters and values and currently a new connection is being opened each time i run it.

My question is how to maintain an open connection?

EDIT: I have control on both sending and receiving end of the request.

MY GOAL: I'm trying to boost speed between two servers (NodeJS is sending HTTP GET to a python simple HTTP server) I want the connection between those two to remain open at all time in order for the requests to be as fast as possible.

TBE
  • 1,002
  • 1
  • 11
  • 32
  • What problem are you trying to solve when you say "how to maintain an open connection"? You just call `request()` and the connection is opened for you automatically so it's no extra work for you so I don't know what problem you're really trying to solve? – jfriend00 Dec 11 '16 at 16:46
  • @jfriend00 I'm trying to boost speed between two servers (NodeJS is sending HTTP GET to a python simple HTTP server) I want the connection between those two to remain open at all time. – TBE Dec 12 '16 at 08:31
  • @TBE Maybe really late but I think you should look into WebSockets. – user12055579 Sep 29 '20 at 19:15
  • 1
    Set the Keep Alive Header – SamAko Mar 20 '21 at 17:56

0 Answers0