0

I am trying to connect to a chat server on the internet from an Android app so first I test whether I have contact with the server from an AsyncTask:

@Override
    protected Void doInBackground(SocketAndEditText... soEd) {
    try{
            InetAddress address1 = InetAddress.getByName("130.237.161.23");
            boolean reachable = address1.isReachable(4456);
            //...
    } catch (Exception e) {
        //...
    }
}

When I run the above code the variable reachable gets the value false but when I run the same code as a simple Java console application I get true:

import java.net.InetAddress;
public class Test {
    public static void main(String[] args) {
        try{
            InetAddress address1 = InetAddress.getByName("130.237.161.23");
            boolean reachable = address1.isReachable(4456);
            System.out.println(reachable);
        } catch (Exception e) {
            //...
        }
    }
}

In my manifest file I have <uses-permission android:name="android.permission.INTERNET" />

Why does it not work in Android but works as a Java application?

RegedUser00x
  • 2,193
  • 5
  • 25
  • 32
  • Apologies I misread your question and I have deleted my answer. It may be useful to point out if the Android device is on the same network as the PC where the Java app runs. Also see http://stackoverflow.com/questions/2935325/android-debugging-inetaddress-isreachable – Rob Kielty May 13 '12 at 22:52
  • Yeah, it's on the same computer. And it seems to work with localhost but not with other addresses. So I turned off the firewall but still no connection :( – RegedUser00x May 13 '12 at 22:55

0 Answers0