By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,804 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,804 IT Pros & Developers. It's quick & easy.

Cannot find the file with java Socket Programming?

P: 28
I want to write socket programming with java.My WebServer class is below.I also have HttpRequest class.
Expand|Select|Wrap|Line Numbers
  1. public final class WebServer
  2. {
  3. public static void main(String argv[]) throws Exception
  4. {
  5. int port = 6787;
  7. // Establish the listen socket.
  9. ServerSocket listenSocket = new ServerSocket(port);
  12.  while (true) {
  13.   // Listen for a TCP connection request.
  14.   Socket connectionSocket = listenSocket.accept();
  16.   // Construct an object to process the HTTP request message
  17.   HttpRequest request = new HttpRequest(connectionSocket);
  19.   // Create a new thread to process the request.
  20.   Thread thread = new Thread(request);
  22.   // Start the thread.
  23.   thread.start();
  24. }
  26. }
  27. }
When I typing

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;
Expand|Select|Wrap|Line Numbers
  1. GET /favicon.ico HTTP/1.1
  2. File not found
  3. <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
File Type: txt WebServer.txt (6.5 KB, 277 views)
Mar 22 '13 #1
Share this Question
Share on Google+
2 Replies

P: 13,264
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.
Mar 23 '13 #2

P: 28
@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..
Mar 23 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.