import java.net.*;
import java.io.*;
..
Socket s = new Socket(hostname, port);
InputStream sin = s.getInputStream()
BufferedReader fromServer = new BufferedReader(new InputStreamReader(sin));
OutputStream sout = s.getOutputStream();
PrintWriter toServer = new PrintWriter(new OutputStreamWriter(sout));
toServer.print("GET " + filename + " HTTP/1.0\n\n");
toServer.flush();
for(String l = null; (l = fromServer.readLine()) != null;)
System.out.println(l);
toServer.close();
fromServer.close();
s.close();
..
import java.io.*;
import java.net.*;
public class HttpMirror {
static class ClientThread extends Thread {
Socket client;
ClientThread(Socket client) { this.client = client; }
public void run() {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(new OutputStreamWriter(client.getOutputStream()));
out.print("HTTP/1.0 200\nContent-Type: text/plain\n\n");
String line;
while((line = in.readLine()) != null) {
if (line.length() == 0) break;
out.println(line);
}
out.close();
in.close();
client.close();
} catch (IOException e) {}
}
public static void main(String[] args) {
try {
..
ServerSocket ss = new ServerSocket(nPort);
for(;;) {
Socket client = ss.accept();
ClientThread t = new ClientThread(client);
t.start();
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
}