Java: socket read time out exception

前端 未结 3 1687
说谎
说谎 2021-01-02 00:44

I trying to make a call to a very heavy duty process. It\'s average work length is estimated by 9-10 minutes.

When I\'m executing the process, I set the timeout for

相关标签:
3条回答
  • 2021-01-02 00:54

    I had the same problem and the solution was not use socket.shutdownInput(); socket.shutDownOutput(); until the last time of reading or writing data to the socket. This made the socket go to FIN_WAIT state thus waiting 2 minutes before closing. You can read more about it in this post

    0 讨论(0)
  • 2021-01-02 00:59

    Clearly you aren't setting the timeout you think you're setting, or someone else is changing it afterwards. You'll have to post some code to get further elucidation.

    Note that according to W.R. Stevens in TCP/IP Illustrated, Vol II, #17.4, the timeout is held in a short as a number of 1000Hz ticks, so a timeout beyond 11 minutes isn't possible. This applies to the BSD code.

    0 讨论(0)
  • 2021-01-02 01:00

    I'm not sure how your application works, but try to set an infinite timeout to the socket

    public void setSoTimeout(int timeout)
                  throws SocketException
    

    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 java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

    If you provide more information about your call, i may improve the answer.

    0 讨论(0)
提交回复
热议问题