/** * Fail Vork.java * @author Jaanus Poial * @version 0.1 kevad 99 */ import java.net.*; import java.io.*; public class Vork { public static void main(String[] parameetrid) throws Exception { //================================================================== // URL //================================================================== String s; if (parameetrid.length > 0) s = parameetrid [0]; else s = "http://www.cs.ut.ee/"; URL viide = new URL (s); System.out.println ("Protocol = " + viide.getProtocol()); System.out.println ("Host = " + viide.getHost()); System.out.println ("Filename = " + viide.getFile()); System.out.println ("Port = " + viide.getPort()); System.out.println ("Ref = " + viide.getRef()); System.out.println ("Sisu:"); BufferedReader sisend = new BufferedReader (new InputStreamReader (viide.openStream())); String rida; while ((rida = sisend.readLine()) != null) System.out.println (rida); sisend.close(); //================================================================= // socket //================================================================= Socket pistik = new Socket ("www.cs.ut.ee", 80); InputStream sisse = pistik.getInputStream(); BufferedReader svoog = new BufferedReader (new InputStreamReader (sisse)); OutputStream valja = pistik.getOutputStream(); PrintWriter vvoog = new PrintWriter (new OutputStreamWriter (valja), true); System.out.println ("Pistiku kaudu:"); vvoog.println ("GET / HTTP/1.0\n"); while ((rida = svoog.readLine()) != null) System.out.println (rida); pistik.close(); } // main lopp } // Vork lopp