有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何理解http put的SocketTimeout?

java.net.Socket#setSoTimeout的javadoc中,它说:

  Enable/disable SO_TIMEOUT with the specified timeout, in
  milliseconds.  With this option set to a non-zero timeout,
  a read() call on the InputStream associated with this Socket
  will block for only this amount of time.  If the timeout expires,
  a <B>java.net.SocketTimeoutException</B> is raised, though the
  Socket is still valid.

对于http put操作,客户机可能会上载一个巨大的文件,客户机总是在写入该文件,而从不从服务器读取数据

在这种情况下,如果我为http客户端设置SocketTimeout,它会在上传过程中抛出TimeoutException吗


共 (1) 个答案

  1. # 1 楼答案

    不,不会。但是,在读取响应代码时,它可能会引发超时异常。如果对等方在上传过程中关闭连接,它将抛出IOException“由对等方重置连接”