我的客戶端首先發送給客戶端併成功從服務器讀取確認。當我再次發送按鈕時,它會寫入服務器,但無法再次讀取。Android Socket in.ReadLine()
繼承人我的代碼:
注:DOIT變量表明,按下按鈕,然後它可以追溯到0,直到用戶再次點擊按鈕。
while (connected) {
try {
Log.d("ClientActivity", "C: Sending command.");
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
doit=1;
Log.e("ErrorButton","NextTime "+doit);
}
});
if(doit==1)
{
Log.e("ErrorButton","If");
////
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.println("Helloo");
while ((text = in.readLine()) != null) {
finall += text;
Log.e("Test","Final: "+finall);
if(text=="quit")
{
socket.close();
}
Log.e("ClientActivity", "After Read "+doit+" "+finall);
// in.close();
doit=0;
Log.e("ClientActivity", "After If "+doit);
}
}
} catch (Exception e) {
Log.e("ClientActivity", "S: Error", e);
}
}
非常感謝。我只注意到它 –