How do I write an applet that connects back to a server?
Arunoday Chatterjee Applets have a restriction that they can connect back only to the server from which it originated. So, to achieve this, the following line of code should be used to open a socket conection back to the originating server:
private static final int SERVERPORT = 1701; Socket clientSock = null; clientSock = new Socket( this.getCodeBase().getHost(), SERVERPORT);The server port can be anything. However, Unix servers restrict user services to be above port 1024. Also, getHost() returns an empty string if the applet was loaded from a file:// URL.