/** @author Agustín J. González */ import java.io.*; import java.net.*; import java.util.Scanner; /** This program makes a socket connection to Electronic Department Web server, and it prints its reply. */ public class ScannerSocketWebTest { public static void main(String[] args) { try { Socket s = new Socket("www.electronica.usm.cl", 80); Scanner in = new Scanner(s.getInputStream()); PrintWriter out = new PrintWriter(s.getOutputStream(), true /* autoFlush */); out.println("GET / HTTP/1.0 \n"); // note that println adds a blank line while (in.hasNextLine()) { System.out.println(in.nextLine()); } } catch (IOException e) { e.printStackTrace(); } } }