【问题标题】:Can i set socket timeout and read timeout in node.js request module?我可以在 node.js 请求模块中设置套接字超时和读取超时吗?
【发布时间】:2016-06-04 03:27:08
【问题描述】:

我使用 node.js(restify) 和请求模块(https://www.npmjs.com/package/request)。 我的节点服务器是代理并请求其他服务器。 我想分别设置套接字超时和读取超时。 像 java 中的 clientSocket.connect / clientSocket.setSoTimeOut。 但是请求模块文档只给出“超时”。

我可以设置套接字超时和读取超时另一个值吗?

【问题讨论】:

    标签: javascript node.js sockets request restify


    【解决方案1】:

    看来你不能。来自文档:

    timeout - Integer containing the number of milliseconds to wait for a server
    to send response headers (and start the response body) before aborting the
    request. Note that if the underlying TCP connection cannot be established, the
    OS-wide TCP connection timeout will overrule the timeout option (the default
    in Linux can be anywhere from 20-120 seconds).
    

    因此,对于实际的连接超时,您依赖于操作系统。如果您可以控制它,您可以根据需要进行更改。

    如果您想要您正在寻找的控件,您可以随时使用 restify 附带的客户端。例如,JSON 客户端的文档显示了以下选项:

    connectTimeout  Number  Amount of time to wait for a socket
    requestTimeout  Number  Amount of time to wait for the request to finish
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 2012-03-21
      • 2012-04-16
      • 2018-07-16
      • 2021-10-18
      • 2017-03-24
      • 1970-01-01
      相关资源
      最近更新 更多