I want to write socket programming with java.My WebServer class is below.I also have HttpRequest class.
When I typing
http://mymachinename:6 787/index.html
the browser says File ./index.txt Not Found.But index.html is in my C:/index.html.I use Classic Eclipse but I run my code in Java EE environment.I controlled whether the port is already used now or not by typing netstat -a -n | find "LIST" from windows command prompt and I saw that I can use port 6787.When I want to make request from browser also I can see what happens from my Console in Eclipse.
For example when I want to get index.html, in console;
How can I fix the problem?Why isn't the file found?
Code:
public final class WebServer
{
public static void main(String argv[]) throws Exception
{
int port = 6787;
// Establish the listen socket.
ServerSocket listenSocket = new ServerSocket(port);
while (true) {
// Listen for a TCP connection request.
Socket connectionSocket = listenSocket.accept();
// Construct an object to process the HTTP request message
HttpRequest request = new HttpRequest(connectionSocket);
// Create a new thread to process the request.
Thread thread = new Thread(request);
// Start the thread.
thread.start();
}
}
}
http://mymachinename:6 787/index.html
the browser says File ./index.txt Not Found.But index.html is in my C:/index.html.I use Classic Eclipse but I run my code in Java EE environment.I controlled whether the port is already used now or not by typing netstat -a -n | find "LIST" from windows command prompt and I saw that I can use port 6787.When I want to make request from browser also I can see what happens from my Console in Eclipse.
For example when I want to get index.html, in console;
Code:
GET /favicon.ico HTTP/1.1 File not found <HTML><HEAD><TITLE>Not Found</TITLE></HEAD><BODY>File ./index.html Not Found</BODY></HTML>
Comment