Is there a way to read the inputstream for a specific amount of time?

后端 未结 4 1910
清歌不尽
清歌不尽 2021-01-19 18:18

I\'ve a situation where a thread opens a telnet connection to a target m/c and reads the data from a program which spits out the all the data in its buffer. After all the da

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-19 19:07

    If you're using a Java Socket for your communication, you should have a look at the setSoTimeout(int) method.

    The read() operation on the socket will block only for the specified time. After that, if no information is received, a java.net.SocketTimeoutException will be raised and if treated correctly, the execution will continue.

提交回复
热议问题