Java Reference
In-Depth Information
OutputStream os = socket.getOutputStream();
PrintStream out = new PrintStream(os);
// read in the first line
System.out.println("**New Request**");
String first = in.readLine();
System.out.println(first);
// read in headers and post data
String line;
do
{
line = in.readLine();
if(line!=null)
System.out.println(line);
} while (line!=null && line.trim().length() > 0);
// write the HTTP response
out.println("HTTP/1.1 200 OK");
out.println("");
out.println("<html>");
out.println("<head><title>Simple Web Server</title></head>");
out.println("<body>");
out.println("<h1>Hello World</h1>");
out.println("<//body>");
out.println("</html>");
// close everything up
out.close();
in.close();
socket.close();
}
/**
* Read in the arguments and start the server.
*
* @param args Web server port.
*/
public static void main(String args[])
{
try
{
if (args.length < 1)
{
System.out.println("Usage:\njava SimpleWebServer [port]");
Search WWH ::




Custom Search