package com.csst.activity;import java.io.ioexception;import com.csst.drawer.r;import android.app.activity;import android.os.bundle;import android.os.handler;import android.os.looper;import android.os.message;import android.os.systemclock;import android.text.textutils;import android.util.log;import android.view.view;import android.widget.button;import android.widget.textview;/** * looper,meeagequeue! * * @author administrator * */public class looperdemoactivity extends Activity { protected static int messagequeueindexid=0; private string [] serveradd={"www.cnblogs.com", "www.iconpng.com", "www.baidu.com", "developers.google.com"}; /** * * Test Ping success Time * * @param addr * @return */ Public long pingsuccesstime (string addr) { runtime run = runtime.getruntime (); process proc = null; Long nowtime=system.currenttimemillis (); try { String str = "ping -c 1 -i 0.2 -w 1 " + addr; system.out.println (str); proc = run.exec (str); int result = proc.waitfor (); if (result == 0) //ping success { long pingsuccEsstime=system.currenttimemillis ()-nowtime; log.e ("Ping", addr+pingsuccesstime+ ""); &NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;PINGSUCCESSTIME;&NBSP;&NBSP;&NBSP;}ELSE{&NBSP;&NBSP;&NBSP;&NBSP;LOG.E (" Ping ", addr+" Pingsuccesstime: "+55554); return 55554; } } catch (ioexception e) { e.printstacktrace (); } catch (interruptedexception e) { e.printstacktrace (); } finally { proc.destroy (); &NBSP;&NBSP;}&NBSP;&NBSP;LOG.E ("Ping", addr+ " Pingsuccesstime: "+55554); return 55554; }  , @Override public void oncreate (bundle icicle) { super.oncreate (icicle); setcontentview (R.layout.looper_ demo_activity); long timetemp=55555; int index=0; for (int i=0;i< serveradd.length;i++) { long time=pingsuccesstime (serverAdd[i]); if (time<timetemp) { index=i; } timeTemp=time; } &NBSP;&NBSP;&NBSP;LOG.E ("ping", "shortest" +index); } }
Android Client selects one of the fastest responding servers