我的客户端第一次发送到客户端并从服务器成功读取确认。当我再次点击发送按钮时,它写入服务器但无法再次读取。
这是我的代码:
注意: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);
}
}