// TalkListener.java
//
// This program is created by modifying an example from the book 
// _Java in a Nutshell_ by David Flanagan. You may study, use, modify, 
// and distribute this example for any purpose. This program is 
// provided WITHOUT WARRANTY either expressed or implied.
//
// Copyright Henrik Björkman 1997
//
// This applet will connect to a port on a server and open
// a window with one field for input from keyboard and one
// field for output received from the server.
//
// History:
// 0.0 Created by Henrik Björkman 1997-05-03
// 0.1 Moved to own file. Henrik 1999-09-08

import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;




// Wait for output from the server on the specified stream, and display
// it in the specified TextArea.
class TalkListener extends Thread 
{
  DataInputStream in;
  TextArea output;

  // Just for debugging.
  static void debug(String s)
  {
    //System.out.println("TalkListner: " + s);   
  }

  public TalkListener(DataInputStream in, TextArea output) 
  {
    this.in = in;
    this.output = output;
    this.start();
    debug("start");
    //output.appendText("testing...\n");
  }

  public void run() 
  {
    String line;
    try 
    {
      for(;;) 
      {
        line = in.readLine();
        if (line == null) break;
        output.appendText(line+"\r\n");
      }
    }
    catch (IOException e) { output.appendText(e.toString()+"\r\n"); }
    finally { output.appendText("Connection closed by server."+"\r\n"); }
  }
}



