|
NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems
ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en:
http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com. |
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂtulo en concreto puede realizar una donación directa mediante Paypal:
|
Applets, like other Java programs, can use the API defined in thejava.netpackage to communicate across the network. The only difference is that, for security reasons, the only host an applet can communicate with is the host it was delivered from.
Note: Depending on the networking environment an applet is loaded into, and depending on the browser that runs the applet, an applet might not be able to communicate with its originating host. For example, browsers running on hosts inside firewalls often cannot get much information about the world outside the firewall. As a result, some browsers might not allow applet communication to hosts outside the firewall.It's easy to find out which host an applet came from. Just use the
AppletgetCodeBasemethod and thejava.net.URLgetHostmethod, like this:String host = getCodeBase().getHost();Once you have the right host name, you can use all the networking code that is documented in the Custom Networking trail.
Note: Not all browsers support all networking code flawlessly. For example, one widely used browser compatible with Java technology doesn't support posting to a URL.
Here's an example of implementing an applet that's a network client.
Here's an example of implementing a server to get around applet security restrictions.