Check out this simple example. Pressing the "Run!" button establishes a connection to google.com on port 80 and sends a nonsense request. It then gets the response text and displays it on the page (don't worry, it's supposed to be an error). View the page source to see how elegant the code is.
Here. Source code is included in case you want to see how it works or need to compile it yourself.
Include the Java applet in the body of your HTML document:
<applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0"> </applet>
Connect to a given url (string) on a given port (integer). Returns true or false depending on success.
Disconnect the current socket. Returns true or false depending on success.
Send a string over the socket. Returns true or false depending on success.
This method is called by the applet every time something comes over the socket from the server. It is blank by default, so overwrite it to handle input.
This method is called by the applet every time an error crops up. It alerts you with the error description by default, so overwrite it to handle errors.
As always, they go to email@example.com.