import java.net.*; import java.io.*; public class WebClient { public static void main (String[] argv) { try { // Open the connection. Socket soc = new Socket ("search.yahoo.com", 80); InetAddress remote_machine = soc.getInetAddress(); System.out.println ("Connected to " + remote_machine); // Now create the output and input streams OutputStream outStream = soc.getOutputStream (); PrintWriter pw = new PrintWriter (outStream); InputStream inStream = soc.getInputStream(); LineNumberReader lnr = new LineNumberReader (new InputStreamReader (inStream)); // 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 (); } // Close streams before quitting. pw.close (); lnr.close (); soc.close (); } catch (IOException e) { System.out.println (e); } } }