import java.net.*;
import java.io.*;
import java.util.*;
import java.awt.*;

public class Client_Basic extends Frame  {

TextArea logDisplay;

  public Client_Basic ()  {

    super ( "Client_Basic " );
    logDisplay = new TextArea ( 40, 10 );
    add ( "Center", logDisplay );
    resize ( 400, 300 );
    show ();

  }  // end Client_Basic constructor

// **************

  public void runClient ( )  {

  Socket connection;
  InputStream input;
  char c;

    try  {
      connection = new Socket ( InetAddress.getByName ("gamma.cs.unc.edu"), 8888 );
      logDisplay.setText ( "Socket created:  connecting to server\n" );
      input = connection.getInputStream ();
      logDisplay.appendText ( "InputStream created\n" );
      logDisplay.appendText ( "Text received from server = \n     " );
      while ( (c = (char) input.read () ) != '\n' ) 
         logDisplay.appendText ( String.valueOf ( c ) ); 
      logDisplay.appendText ( "\n" );
      connection.close ();
      logDisplay.appendText ( "Connection closed\n" );
    }  // end try

    catch ( IOException except)  {
      except.printStackTrace ();
    }  // end catch

  }  // end runClient 

// **************

  public boolean handleEvent ( Event event )  {

    if ( event.id == Event.WINDOW_ICONIFY )  {
      hide ();
      dispose ();
      System.exit ( 0 );
    }  // end if

    return super.handleEvent ( event );

  }  // end handleEvent 

// **************

  public static void main ( String [ ] args )  {

    Client_Basic client = new Client_Basic ();
    client.runClient ();

  }  // end main

}  // end Client_Basic


