-1
這是正確的嗎?或者我在這裏做錯了什麼?soTimeout從你打電話的那一刻開始打嗝?
設置超時的話,從插座
public String receive(){
inStream = telnetCreator.getInputStream(client);
int buff;
String MessageReceived ="";
try{
if (inStream.available() > 0){
buff = inStream.read();
MessageReceived += (char) buff;
System.out.println(MessageReceived);
}
}catch (Exception e){
System.out.println("MessageReceived :- "+ MessageReceived);
return MessageReceived;
}
return MessageReceived;
}
因爲我設置超時時間爲1000毫秒,然後睡了2000毫秒閱讀
client.setSoTimeout(1000); // timeout after READ_SlEEP if the socket is idle
Thread.sleep(2000);
,插座拋出一個異常因爲讀取的定時器已經超時。 這很刺激。那麼現在我必須在使用接收之前設置超時,然後在每次接收後清除超時?
1.我不想等待1秒以上號。 – badbuddha
我正嘗試連接到遠程登錄服務器。我想發送一條消息,然後等待1秒鐘作出迴應。所以服務器的請求響應之王。我必須多次這樣做。但是如果我在兩次請求 - 響應之間有睡眠,那麼它表示讀取超時 – badbuddha