/** @author Agustín J. González */ import java.io.*; import java.net.*; /** This program makes a socket connection to Electronic Department Web server, and it prints its reply. */ public class SocketWebTest { public static void main(String[] args) { try { Socket s = new Socket("www.electronica.usm.cl", 80); // create a client socket connected to web server BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); // two // adaptation classes to access higher level methods PrintWriter out = new PrintWriter(s.getOutputStream(), true /* autoFlush */); out.print("GET / HTTP/1.0 \n"); out.println("Host:www.electronica.usm.cl\n"); // note that println adds a blank line boolean more = true; while (more) { String line = in.readLine(); if (line == null) more = false; else System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } }