我做了个TCP/IP通信,在socket通信时,服务器端没开的话,我做的客户端是黑屏什么都不显示,这时我想做个提醒,“正在连接服务器”,怎么搞,我把我的代码粘上,高手给个指点
public void load(){//初始化时与服务器建立连接
try {
Toast.makeText(getApplicationContext(), "请等待正在与服务器连接...",Toast.LENGTH_LONG).show();
_socket = new Socket(SERVERIP, SERVERPORT);
if(_socket.isConnected()){//socket连接上
// 取得输入/输出流
//_bufferedReader = new BufferedReader(new InputStreamReader(_socket.getInputStream(), "GB2312"));
_printWriter = new PrintWriter(_socket.getOutputStream(), true);
// 开启监听线程
_thread.start();
}else{//socket没有连接上
Toast.makeText(getApplicationContext(), "与服务器连接失败,请等待...",Toast.LENGTH_SHORT).show();
int isconnect=1;
while(isconnect==1){
_socket = new Socket(SERVERIP, SERVERPORT);
Thread.sleep(100);//停100毫秒
if(_socket.isConnected()){
isconnect=0;
}
}
}
}
catch (Exception e) {
System.out.println("Connect is failed!");
(
}
}
------解决方案--------------------
不用Toast 用dialog
------解决方案--------------------
用ProgressDialog
------解决方案--------------------
同求 请指点
------解决方案--------------------
Toast.LENGTH_LONG).show();