本文为大家分享了模拟 ping 操作的一个 java 类 , 具体内容如下 具体内容如下
Java.io.ioException importieren; import java.net.inetaddress; import java.net.unnownhostexception; /** * Erstellt von Qiuju * am 2014/9/21. */public class SimplePing implementiert runnable {private endgültige Objekt mendlock = new Object (); privat boolean isend = false; private int angekommene ccount = 0; private Int Count; private int Timeout; privater Zeichenfolge Name; privat int mendcount; private String mip = null; privat float mloSSrate = 1f; private float mdelay = 0; public simping (String -Name, int count, int timeout) {count = mendCount = count; Timeout = Timeout; Name = Name; für (int i = 0; i <mendcount; i ++) {Thread = neuer Thread (this); thread.setdaemon (true); Thread.Start (); } if (! isend) {try {synchronized (mendlock) {mendlock.wait (); }} catch (interruptedException e) {e.printstacktrace (); }}} private void setend (boolean isArlived, Long Delay, String IP) {synchronisiert (Mendlock) {count--; if (isArlived) {angekommener Count ++; mdelay = (mdelay + delay) / 2f; if (ip! = null) mip = ip; }} if (count == 0) setend (); } private void setend () {MLOSSRATE = (MendCount - angekommen) / MendCount; Isend = wahr; synchronisiert (mendlock) {mendlock.notifyall (); }} @Override public void run () {Long Delay = 0; boolean isArived = false; String ip = null; try {long start time = system.currentTimemillis (); Inetaddress address = inetaddress.getbyName (Name); isArived = address.isreantable (Timeout); Delay = System.currentTimemillis () - StartTime; ip = address.gethostaddress (); } catch (unbekannteHostException e) {e.printstacktrace (); } catch (ioException e) {e.printstacktrace (); } catch (Ausnahme e) {e.printstacktrace (); } endlich {setend (isArlived, delay, ip); }} public String getIp () {return mip; } public float getlosSrate () {return mLosSrate; } public float getDelay () {return mdelay; } public boolean getIssuccepe () {return angekommener Count> 0; }}在类中使用的是 :
Long start time = system.currenttimemillis (); Inetaddress address = inetaddress.getbyName (Name); isArived = address.isreantable (Timeout); Delay = System.currentTimemillis () - StartTime; ip = address.gethostaddress ();
其中的 : adresse.isantierbar (Zeitüberschreitung);
之所以说是中间类 , 也就是因为这个原因没有采用这个类。 也就是因为这个原因没有采用这个类。
以上就是本文的全部内容 , 希望对大家的学习有所帮助。 希望对大家的学习有所帮助。