13241

How do I set a socket connection timeout in node.js http client

Question:

Is there a way to set a socket connection timeout in node.js http.request?

I'm not looking to set a http request timeout but a connection timeout.

Answer1:

Use req.socket.setTimeout(30000); This overrides the default of having no timeouts for sockets. Be aware that the timeout event will not automatically close the connection, you'll have to do that yourself when you handle the event, usually by calling end() or destroy on the socket. You can also add a one-time-callback as an optional parameter.

Recommend

  • Selenium WebDriver setting ImplicitlyWait does nothing
  • asp.net login page issue
  • Is there a way to stop/re-start ejb 3.1 automatic timer during runtime?
  • Custom Animation Object for Transition in Android?
  • Why String.ToString()? [duplicate]
  • SiteMesh: Changing the content-type of the response
  • SMT prover yields 'unknown' despite strong proven assertions
  • How to send an std::vector of unsigned char over an UDP socket using boost asio?
  • Seamless scrolling text
  • IE8 stops network access after 5 long polling request
  • How to read data from socket connection - android
  • Cannot send user message with Spring Websocket
  • Global session variable in express.js route?
  • setTimeOut and local function
  • parsing xml and html page with lxml and requests package in python
  • Sort an arraylist of objects in java
  • Express JS Display Data By ID
  • Python: sending key press events over SSH
  • Error in making a socket connection
  • CORS with socket.io
  • Check for zero lines output from command over SSH
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Modifying destination and filename of gulp-svg-sprite
  • Symfony2: How to get request parameter
  • Display Images one by one with next and previous functionality
  • GridView Sorting works once only
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Turn off referential integrity in Derby? is it possible?
  • Qt: Run a script BEFORE make
  • JaxB to read class hierarchy
  • reshape alternating columns in less time and using less memory