I want to make a simple http server like this
import java.net.*;
import java.io.*;
public class MyHttpServer {
/** Creates a new instance of MyHttpServer */
public MyHttpServer() {
}
public void run()
{
try
{
int port = 10000;
ServerSocket srv = new ServerSocket(port);
// Wait for connection from client.
Socket socket = srv.accept();
System.out.println("Hello"
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
wr.write("Content-Type: text/html\r\n"
wr.write("<HTTP><BODY>OK</BODY></HTTP>"
wr.flush();
}
catch (IOException e) {
}
}
}
My i-explorer probe is:
htt://localhost:10000
The browser found nothing, and my class MyHttpServer write "Hello".
Why?
Is this method of work correct? or is this a barbarism?
Thanks.
import java.net.*;
import java.io.*;
public class MyHttpServer {
/** Creates a new instance of MyHttpServer */
public MyHttpServer() {
}
public void run()
{
try
{
int port = 10000;
ServerSocket srv = new ServerSocket(port);
// Wait for connection from client.
Socket socket = srv.accept();
System.out.println("Hello"
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
wr.write("Content-Type: text/html\r\n"
wr.write("<HTTP><BODY>OK</BODY></HTTP>"
wr.flush();
}
catch (IOException e) {
}
}
}
My i-explorer probe is:
htt://localhost:10000
The browser found nothing, and my class MyHttpServer write "Hello".
Why?
Is this method of work correct? or is this a barbarism?
Thanks.