11

Android アプリケーションを開発しており、IPv6 を使用してサーバーに接続する必要があります。

電話機で IPv6 が有効になっており、自分のローカル IPv6 アドレスが で表示されip addrます。ping6また、PC から電話を使用することも、その逆も可能です。

しかし、Java コマンドNetworkInterface.getNetworkInterfaces()を使用して Android でローカル アドレスを取得しようとすると、IPv4 アドレスしか取得できません。

また、クライアントソケットを開こうとしましたが、行 Socket s = new Socket(MYSERVERIPV6ADDRESS, PORT); は常にjava.net.SocketException: Invalid argument. コンピューターで同じコードを試してみたところ、完全に機能したため、アドレスは正しいと確信しています。

オペレーティング システムでは IPv6 がサポートされていますが、Java 仮想マシンではサポートされていないようです。この問題を解決する方法はありますか?

4

2 に答える 2

2

Inet6Address でこの静的メソッドを使用して、アドレスの Inet6Address オブジェクトを取得します。

Inet6Address getByAddress (文字列ホスト、byte[] addr、int scope_id)

次に、次のソケット コンストラクターを使用してソケットを取得します。

Socket(InetAddress dstAddress, int dstPort)。

于 2012-05-12T11:31:24.243 に答える
1

IP6 support is the choice of the vendor to include, to my understanding, support is there.

I am assuming you are testing you app in emulator. Looking at how android does networking, http://developer.android.com/guide/developing/devices/emulator.html#emulatornetworking It's behind an IPv4 router addressed 10.0.2.1. Hence, you are not able to open a Socket using IPv6. It's all dependent if a path exists of all the routers who are IPv6 compatible from your phone to your destination.

于 2012-05-12T11:48:45.213 に答える