import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.lang.reflect.Field;
import java.util.List;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
class Handler implements HttpHandler {
private static final Charset UTF8 = Charset.forName("utf-8");
public void handle
(final HttpExchange exchange
) throws IOException { try {
Field f
= exchange.
getClass().
getDeclaredField("impl"); f.setAccessible(true);
f = obj.getClass().getDeclaredField("connection");
f.setAccessible(true);
obj = f.get(obj);
f = obj.getClass().getDeclaredField("chan");
f.setAccessible(true);
SocketChannel chan = (SocketChannel) f.get(obj);
System.
out.
println("Remote address: " + chan.
getRemoteAddress()); e.printStackTrace();
}
try {
{
while ((s = reader.readLine()) != null) {
System.
out.
println("Input: " + s
); }
}
for (int j = 0; j < 3; ++j) {
os.write(("Lesson #" + (j + 1)).getBytes(UTF8));
for (int i = 0; i < 10; ++i) {
os.write("I will use Google before asking dumb questions".getBytes(UTF8));
}
os.flush();
}
}
e.printStackTrace();
}
}
}
public class Main {
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.createContext("/", new Handler());
server.setExecutor(null);
server.start();
server.stop(0);
}
}