简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM