Because we are an Applet, we can only talk to the host that we were loaded from. We find out the name of the machine using Applet methods getCodeBase() to find the URL of the host and then getHost() to find the machine's internet name.
To perform stream data I/O through the socket, we get hold of the DataInputStream and DataOutputStream objects for the socket (note that we do not create new streams, they are created along with the socket object).
The actual Input and Output is the same for the socket's data streams as for any other data streams (e.g. files).
This example also shows how easy it is to create a simple Java Graphical User Interface. All we do is create new objects of the appropriate classes for each GUI element (buttons, text areas etc.) and 'add' them to the applet. To handle button presses, we catch events by overloading the applet "action()" method.