socket and setSoTimeout()

后端 未结 2 573
抹茶落季
抹茶落季 2021-01-28 13:11

I am quite confused about socket.setSoTimeout( int ) method.

In scenario when i call

 socket.setSoTimeout(4000);
 try{
      string data = input.read();
         


        
2条回答
  •  一整个雨季
    2021-01-28 13:52

    I think,setSotimeout denotes the amount of time a server can wait for a response to read.if timeout value exceeds ,exception will be thrown.

    for example.If you set setSotimeout(4000) to socket,

    Socket will wait for only 4 secs for the receiver to respond,it throws exception after 4 secs.

    It will be useful in slow connection networks or bad servers. It avoids waiting for response.

提交回复
热议问题