// File: IO24.java (Module 13) // // Author: Rahul Simha // Created: Nov 30, 1998 // // Using HTTP GET for a query. import java.net.*; import java.io.*; public class IO14 { public static void main (String[] argv) { try { // Open the connection. Socket soc = new Socket ("search.yahoo.com", 80); InetAddress remoteMachine = soc.getInetAddress(); System.out.println ("Connected to " + remoteMachine); // Now create the output and input streams OutputStream outStream = soc.getOutputStream (); PrintWriter pw = new PrintWriter (outStream); InputStream inStream = soc.getInputStream(); InputStreamReader isr = new InputStreamReader (inStream); LineNumberReader lnr = new LineNumberReader (isr); // Make the query. pw.print ("GET /bin/search?p=java\n\n"); pw.flush (); // Get the results. String s = lnr.readLine (); while (s != null) { System.out.println (s); s = lnr.readLine (); } pw.close (); lnr.close (); soc.close (); } catch (IOException e) { System.out.println (e); } } }