/**{f}
*
SimpleWebClient.java
*
Classe che
apre una connessione ad un server
* web e legge una singola pagina web dalla connessione
*
attraverso l'uso di socket
*
@version 1.00 01/03/10
*
@author Bertolini Marta & Girotto Cristiano
*/
import
java.io.*;
import
java.net.*;
public
class SimpleWebClient {
public static void main(String args[])
{
try
{
// apre una connessione socket
Socket clientSocket1 =
new Socket(args[0], 25);
System.out.println("Client1: " + clientSocket1);
System.out.println("Client1 SO_LINGER: " +
clientSocket1.getSoLinger());
System.out.println("Client1
SO_TIMEOUT: " + clientSocket1.getSoTimeout());
System.out.println("Client1 TCP_NODELAY: " +
clientSocket1.getTcpNoDelay());
getPage(clientSocket1);
}
catch (UnknownHostException uhe)
{
System.out.println("UnknownHostException: " + uhe);
}
catch (IOException ioe)
{
System.err.println("IOException: " + ioe);
}
}
/**
* richiesta di una pagina web utilizzando il client socket passato
* visualizza e chiude il client socket
*/
public static void getPage(Socket clientSocket)
{
try
{
// Acquisisce l' input e l'output streams
DataOutputStream
outbound = new DataOutputStream(
clientSocket.getOutputStream() );
BufferedReader inbound = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
// scrive la richiesta HTTP al server
outbound.writeBytes("GET / HTTP/1.0\r\n\r\n");
String responseLine;
while ((responseLine = inbound.readLine()) != null)
{
// visualizza ciascuna linea
System.out.println(responseLine);
}
outbound.close();
inbound.close();
clientSocket.close();
}
catch (IOException ioe)
{
System.out.println("IOException: " + ioe);
}
}
}