473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
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;
  6.  
  7. // Establish the listen socket.
  8.  
  9. ServerSocket listenSocket = new ServerSocket(port);
  10.  
  11.  
  12.  while (true) {
  13.   // Listen for a TCP connection request.
  14.   Socket connectionSocket = listenSocket.accept();
  15.  
  16.   // Construct an object to process the HTTP request message
  17.   HttpRequest request = new HttpRequest(connectionSocket);
  18.  
  19.   // Create a new thread to process the request.
  20.   Thread thread = new Thread(request);
  21.  
  22.   // Start the thread.
  23.   thread.start();
  24. }
  25.  
  26. }
  27. }
When I typing

http://mymachinename:6787/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;
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, 341 views)
Mar 22 '13 #1
2 1584
r035198x
13,262 8TB
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
@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

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

Similar topics

13
by: Brad | last post by:
I will also post this in the CR group but because I program in VB maybe somebody here might be able to help. I am working on a new project that incorporates a few forms. I just created my first...
3
by: mo | last post by:
I have an application that uses Reporting Services. When the user chooses to print a report, they are taken to a window that allows them to fill in parameters for the report. They then click a...
1
by: hypermommy | last post by:
Hi all, I have a problem that's got me just stumped. On my local machine (WinXPPro) my application runs just fine. But on the client's server (Win2003ServerStandard) when I try to pull up my...
1
by: marty.gagnon | last post by:
I have a xsl file that references a xml file using the document() function. I'm having trouble specifying the URI in the document() function of a xls stylesheet. I'm using java to transform the...
1
by: .Net Sports | last post by:
I'm using Persits.upload module in ASP, and when i use the following form pointed to the object I've always used, i get a "The system cannot find the file specified" error pointing to the line of...
9
by: phantom3008 | last post by:
Hi i want to record an audio file and send it using UDP . I have server/client program and i'm able to send text file and recive that into another file .But how do i send audio file ..can anyone help...
1
by: Seriph | last post by:
Hey I just installed Textpad ver 4.something and writen up a simple println program, but I cant compile it. I keep getting the message "cannot find the file specified" with...
5
by: ranajui | last post by:
design a protocol where the communication between a client and a server is established by means of socket connection in java.
2
by: rayoflight | last post by:
This is how my test program works. Server will encrypt some text and sends it over to the client. The client will then decrypts it. However I have some problem decrypting it. When I play...
1
by: Rohan Thakare | last post by:
i am having a file containg data for students name and their marks. i am sending this file from client to server using Socket clientSocket = new Socket("127.0.0.1", portNo); OutputStream os =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.