// Create a socket to communicate with a server on port 6789 of the
// host that the applet's code is on. Create streams to use with
// the socket. Then create a TextField for user input and a TextArea
// for server output. Finally, create a thread to wait for and
// display server output.
try {
s = new Socket(this.getCodeBase().getHost(), PORT);
in = new DataInputStream(s.getInputStream());
out = new PrintStream(s.getOutputStream());
inputfield = new TextField();
outputarea = new TextArea();
outputarea.setEditable(false);
this.setLayout(new BorderLayout());
this.add("North", inputfield);
this.add("Center", outputarea);
listener = new StreamListener(in, outputarea);
this.showStatus("Connected to "
+ s.getInetAddress().getHostName()
+ ":" + s.getPort());
}
catch (IOException e) { this.showStatus(e.toString()); }