import java.net.*;
import java.io.*;


        // Use the HTTP server running on hostname.
class HTTPClient extends TCPEndpoint {
        // Contact the server at the appropriate port and set
        // the socket attribute for the run() method to use.
    public HTTPClient(String hostname) throws Exception {
        // The well-known port of the HTTP service.
        super(hostname,HTTPPort);
    }

        // Retrieve the given filename from the HTTP server.
    public String retrieve(String filename) throws IOException {
        try{
            // Send the retrieval command.
            // Use the HTTP/0.9 Simple-Request.
            sendLine("GET "+filename);
            // The line to be returned will be built up in this.
            StringBuffer line = new StringBuffer();
            // Read and print the responses.
            String response = getLine();
            while(response != null){
                line.append(response+"\n");
                response = getLine();
            }
            return line.toString();
        }
        finally{
            // Close the connection now it is finished with.
            close();
        }
    }

    // The well-known port of the HTTP server.
    private static final int HTTPPort = 80;
}
