
/**
 *  NetClient is a program that makes a network connection to a server.
 *  The server is running on some specific "host" computer and is
 *  listening on a specific "port".  To use this program, the user must
 *  know the Internet name (or IP number) of the server computer and the
 *  port on which it is listening.  The program asks the user for this
 *  informaion, and then makes the connection.  Once the connection has
 *  been made, the computer gets a line of text from the user and sends
 *  it to the server.  Finally, it waits for a one-line response from
 *  the server and displays the response to the user.
 */


public class NetClient {

   public static void main(String[] args) {
      
      String host;    // The name or IP number of the server computer.
      int port;       // The port number on which the server is listening.
      String message; // A line of text transmitted over the network.
      
      // Get the host name and port number from the user.
      
      System.out.println();
      System.out.print("What computer do you want to connect to? ");
      host = TextIO.getln();
      System.out.print("What port number do you want to use?     ");
      port = TextIO.getlnInt();
      
      // Make a connection to the server.
      
      Network.connect(host,port);
      
      // Get a line of text from the user and send it over the connection.
      
      System.out.print("Enter your message:  ");
      message = TextIO.getln();
      Network.send(message);
      
      // Wait for a reply from the server and display it to the user.
      
      System.out.println("Message sent.  Waiting for reply...");
      message = Network.receive();
      System.out.println("RECEIVED REPLY:  " + message);
      System.out.println();
      
      // Close the connection.

      Network.close();
      
   } // end main()

} // end clsss NetServer
