Android Open Source - android_asyncsocket Dns Resolver






From Project

Back to project page android_asyncsocket.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project android_asyncsocket 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 com.smorra.asyncsocket;
/*w ww . ja  va2  s.co m*/
import java.io.IOException;
import java.net.InetAddress;

import android.os.Handler;
import android.os.Looper;

public class DnsResolver extends Thread
{
  DnsResolverCallback drc;
  String hostName;
  boolean cancelled = false;

  public DnsResolver(DnsResolverCallback drc, String hostName)
  {
    this.drc = drc;
    this.hostName = hostName;
    start();
  }

  public void cancel() throws IOException
  {
    if (cancelled)
      throw new IOException("already cancelled");
    cancelled = true;
  }

  public void run()
  {
    try
    {
      final InetAddress[] ia = InetAddress.getAllByName(hostName);
      new Handler(Looper.getMainLooper()).post(new Runnable()
      {

        @Override
        public void run()
        {
          if (cancelled)
            return;
          drc.onResolved(ia);
        }
      });
    }
    catch (Exception e)
    {
      System.out.println("FAILED");
      e.printStackTrace();
      new Handler(Looper.getMainLooper()).post(new Runnable()
      {

        @Override
        public void run()
        {
          if (cancelled)
            return;
          drc.onResolveFailed();
        }
      });
    }
  }
}




Java Source Code List

com.smorra.asyncsocket.DnsResolverCallback.java
com.smorra.asyncsocket.DnsResolver.java
com.smorra.asyncsocket.SSLClientCallback.java
com.smorra.asyncsocket.SSLClient.java
com.smorra.asyncsocket.TcpClientCallback.java
com.smorra.asyncsocket.TcpClient.java
com.smorra.asyncsocket.TcpServerCallback.java
com.smorra.asyncsocket.TcpServerClientCallback.java
com.smorra.asyncsocket.TcpServerClient.java
com.smorra.asyncsocket.TcpServer.java