[英]Can i set socket timeout and read timeout in node.js request module?
我使用node.js(restify)和请求模块( https://www.npmjs.com/package/request )。 我的节点服务器是代理服务器,并请求其他服务器。 我想设置套接字超时并分别读取超时。 像java中的clientSocket.connect / clientSocket.setSoTimeOut一样。 但是请求模块文件仅给出“超时”。
我可以设置套接字超时并读取超时值吗?
看来您没有能力。 从文档中:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.