rivate Button send;
private TextView rec;
private static Socket client;
private PrintWriter write;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rec=(TextView)findViewById(R.id.textView3);;
Thread aa=new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
//服務器的ip的地址 和端口號
client=new Socket(InetAddress.getByName("192.168.1.101"),4312);
BufferedReader read=new BufferedReader
(new InputStreamReader(client .getInputStream()));
rec.setText("123");
String s = "";
while(true){
s=read.readLine();
rec.setText(s);
}
}
catch(IOException e){
rec.setText("123123");
}
}
});
aa.start();
}
在 while(true){ s=read.readLine(); rec.setText(s); }為什麼只能接收服務器的一次消息第二次手機就會跳出程序
要考慮沒有收到數據時,要怎麼處理