/** @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); BufferedReader in = new BufferedReader (new InputStreamReader(s.getInputStream())); PrintWriter out = new PrintWriter (s.getOutputStream(), true /* autoFlush */); out.print("GET / HTTP/1.0 \n"); // note that println adds a blank line 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(); } } }