/* Vernetzte Systeme, WS 2001/2002, Uebung 5, Aufgabe 21 b * * Demonstration des HTTP/1.0-Protokolls: * Nutzung von Reader- und Writer-Klassen, um Daten zu lesen. */ import java.net.*; import java.io.*; public class UserAgent21b { public static void main(String[] args) throws Exception { Socket mySocket = new Socket(args[0], 80); /* PrintWriter PrintStream * Contain convenient printing methods. These are the easiest * streams to write to, so you will often see other writable * streams wrapped in one of these. */ PrintWriter out = new PrintWriter (mySocket.getOutputStream(), true); /* InputStreamReader and OutputStreamWriter * A reader and writer pair that forms the bridge between *byte* * streams and *character* streams. An InputStreamReader reads * bytes from an InputStream and converts them to characters * using either the default character-encoding or a * character-encoding specified by name. Similarly, an * OutputStreamWriter converts characters to bytes using either * the default character-encoding or a character-encoding * specified by name and then writes those bytes to an * OutputStream. */ BufferedReader in = new BufferedReader( new InputStreamReader( mySocket.getInputStream())); // send request (PrintWriter contains 'println' method) out.println("GET " + args[1] + " HTTP/1.0"); out.println(); // read answer String inputline; while (((inputline = in.readLine()) != null) && (inputline.length() > 0)) { System.out.println(inputline); } out.close(); in.close(); } // of main } // of UserAgent22b class