【问题标题】:How to understand SocketTimeout for http put?如何理解 http put 的 SocketTimeout?
【发布时间】:2014-02-03 21:39:01
【问题描述】:

来自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?

【问题讨论】:

    标签: java sockets http timeout


    【解决方案1】:

    不,不会。但是,在读取响应代码时可能会引发超时异常。如果对端在上传过程中关闭连接,会抛出 IOException 'connection reset by peer'。

    【讨论】:

      猜你喜欢
      • 2017-04-03
      • 1970-01-01
      • 2022-06-27
      • 2010-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-19
      • 2011-01-02
      相关资源
      最近更新 更多