Back to project page android_asyncsocket.
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.
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(); } }); } } }