/**
* 心跳线程,每隔一段时间与服务器通信,发送的数据是:1,也可以制定你们想要的数据
*/
private Runnable HeartBeatRunnable = new Runnable() {
@Override
public void run() {
if(System.currentTimeMillis() – lastTime >= TAKT_TIME){
boolean status = sendMsg(“1″);
if(!status){
mHandler.removeCallbacks(HeartBeatRunnable);
releaseLastSocket(mSocket);
mReadThread.release();//释放线程
initSocket();//重建线程
}
mHandler.postDelayed(HeartBeatRunnable, TAKT_TIME);//继续发送心跳包
Log.d(TAG,”HeartBeatRunnable”);
}
}
};
近期评论