Android Open Source - mpiwifi D N S Resolver






From Project

Back to project page mpiwifi.

License

The source code is released under:

GNU General Public License

If you think the Android project mpiwifi listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.sorz.mpiwifi;
/*from   w w w.j  ava2  s  .  c  o  m*/
import java.net.InetAddress;
import java.net.UnknownHostException;

public class DNSResolver implements Runnable {
  private String domain;
  private InetAddress inetAddress;

  DNSResolver(String domain) {
    this.domain = domain;
  }

  @Override
  public void run() {
    try {
      setAddr(InetAddress.getByName(domain));
    } catch (UnknownHostException e) {
      inetAddress = null;
    }
  }

  private synchronized void setAddr(InetAddress inetAddress) {
    this.inetAddress = inetAddress;
  }

  public synchronized InetAddress getAddr() {
    return inetAddress;
  }

  public static InetAddress lookup(String host, int timeout)
      throws UnknownHostException {
    DNSResolver dnsResolver = new DNSResolver(host);
    Thread thread = new Thread(dnsResolver);
    thread.start();
    try {
      thread.join(timeout);
    } catch (InterruptedException e) {
      throw new UnknownHostException();
    }
    InetAddress inetAddress = dnsResolver.getAddr();
    if (inetAddress == null)
      throw new UnknownHostException();
    else
      return inetAddress;
  }
}




Java Source Code List

org.sorz.mpiwifi.DNSResolver.java
org.sorz.mpiwifi.MainActivity.java
org.sorz.mpiwifi.NetworkBroadcast.java
org.sorz.mpiwifi.WifiLoginService.java
org.sorz.mpiwifi.WifiLoginer.java
org.sorz.mpiwifi.exceptions.AlreadyConnectedException.java
org.sorz.mpiwifi.exceptions.LoginFailException.java
org.sorz.mpiwifi.exceptions.NetworkException.java
org.sorz.mpiwifi.exceptions.NoNetworkAccessException.java
org.sorz.mpiwifi.exceptions.UnknownNetworkException.java