How can I connect to an IPv6 address on Android?

yydl picture yydl · Nov 25, 2013 · Viewed 18.3k times · Source

On Android, I'm using HttpClient to connect to a web address like so:

String url = "http://[fe80::1cef:49e7:2661:ffda]:7001/a.MOV";
HttpParams httpParameters = new BasicHttpParams();
HttpClient client = new DefaultHttpClient(httpParameters);
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);

The code works fine when inputting a standard URL, or one with a v4 IP address. However, when I use a v6 address, the last line of the above code will fail with a java.net.SocketException: Invalid argument being thrown.

To illustrate, while this address:

http://192.168.1.2:7001/a.MOV

will work without a problem, this one:

http://[fe80::1cef:49e7:2661:ffda]:7001/a.MOV

won't work at all.

To be sure, I also tried using the newer HttpURLConnection to make the connection, and it still results in the same exception being thrown.

I'm currently performing my testing on a Google TV device running Android version 3.2.

So is there something I'm doing wrong? And if not, is there any way to work around this apparent limitation of Android?

Answer

Viswanath Lekshmanan picture Viswanath Lekshmanan · Nov 25, 2013

Since you are using Android 3.2 It will not support ipv6

Check here https://android.stackexchange.com/questions/3718/does-android-have-support-for-ipv6