Cannot find the file with java Socket Programming?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • notfound
    New Member
    • Jun 2012
    • 28

    Cannot find the file with java Socket Programming?

    I want to write socket programming with java.My WebServer class is below.I also have HttpRequest class.
    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();
    }
    
    }
    }
    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;
    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>
    How can I fix the problem?Why isn't the file found?
    Attached Files
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    There is no link between your code that opens a socket and your html file on your disk. If you want to serve html pages then develop a web application and deploy it to a proper webserver.

    Comment

    • notfound
      New Member
      • Jun 2012
      • 28

      #3
      @r035198x I have solved the problem.I was trying to get from my C driver but when I want to add som e another files to my eclipse workspace I worked and I got the file in my browser.Thanks. .

      Comment

      Working...