サーバーからの応答を読み取ろうとしています。私には2つの方法があります。最初のものはブロックしませんが、2番目のブロックはブロックします。私は理解していない理由の違い..ソケットブロックから読み取る
方法1:
public static String lireReponse() throws IOException, NullPointerException {
// recepteurReponses is a BufferedInputStream
String reponse = "";
byte[] flux = new byte[1024];
int i = recepteurReponses.read(flux);
reponse += new String(flux, 0, i);
return reponse;
}
方法2:
public static String lireDonnees() throws IOException, NullPointerException {
String reponse = "";
byte[] flux = new byte[1024];
int i = -1;
while ((i = recepteurReponses.read(flux)) != -1)
reponse += new String(flux, 0, i);
return reponse;
}
'recepteurReponses'はいつも閉じていますか? –
私が最初の方法でブロックしないのは、クライアントが応答を得て、それをconsole.Andで印刷できるということです。クライアントがCLOSEリクエストをサーバーに送ると、recepteurReponsesは閉じます – Mouley