/* * Vorlesung "Vernetzte Systeme" WS 2000/2001, Prof. Dr. F. Mattern * ---------------------------------------------------------------- * Aufgabe 22a * * Pointers: * * - Mehr ueber Lesen und Schreiben von/auf Datenstroemen: * http://java.sun.com/docs/books/tutorial/essential/io/index.html * * */ import java.net.*; // Hier importieren wir uns1ere Socket "toolbox" // http://java.sun.com/docs/books/tutorial/essential/io/overview.html import java.io.*; // Damit können wir Zeichen lesen und ausgeben public class UserAgent22a { 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. */ InputStreamReader in = new InputStreamReader(mySocket.getInputStream()); // send request (PrintWriter contains 'println' method) out.println("GET " + args[1] + " HTTP/1.0"); out.println(); // read answer int nextchar; while ((nextchar = in.read()) != -1) { System.out.print((char)nextchar); } out.close(); in.close(); } // of main } // of UserAgent class