How to determine if an applet was loaded via IPv6
I have an applet that connects back to a service running on the same host. The webserver that hosts the applet listens on both IPv4 and IPv6 as does the service that the applet wants to connect to.
The problem is that from the with in the applet all I can get is the page URL or the Codebase URL. From the the URL I can't detect if it was resolved to a IPv4 or IPv6 by the browser so when the applet was loaded via IPv6 and I use the URL to tell the applet which server to look for the service on it fails the Sandbox rules as it defaults to resolving to the IPv4 address.
The only solution that comes to mind is to sign the applet so it can request to connect to arbitrary servers, but I was hoping for a simpler solut开发者_如何学编程ion (that doesn't involve buying certs or adding my custom CA to the truststore on all systems accessing the site).
Anybody got a better solution.
Use InetAddress.getAllByName(). The order of the results will tell you which you should use (namely, you should try to use result[0] first).
The important question is not "how was the applet loaded", but "how should I connect to the host".
精彩评论