Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 30th, 2004, 11:51 PM   #1
searcher
Newbie
 
Join Date: Oct 2004
Posts: 2
Rep Power: 0 searcher is on a distinguished road
I have wrote a web server by C language.
but I don't know how to send back error page to web browser if user type wrong web address or name that will show HTTP/1.0 404 NOT FOUND.

One more is how I can stop server socket sending rubbish code if the requested files are sent competely.

Thanks
searcher is offline   Reply With Quote
Old Oct 30th, 2004, 11:57 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Theres no way we can tell you how to fix your code if we dont have it..
__________________

tempest is offline   Reply With Quote
Old Oct 31st, 2004, 1:16 AM   #3
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Well, the code itself doesn't exactly need fixed. I think he is asking how servers do this in general..

I'm not sure how this works myself, but if I had to guess I would think it would have something to do wtih some sort of if statement. If certain directory or file doesn't exist, then send errorPage.html. Something a long those lines.
thechristelegacy is offline   Reply With Quote
Old Oct 31st, 2004, 1:47 AM   #4
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Well if he wrote a HTTP server, then he should be able to write basic code like that... but what i said was basically acting on the idea that he didnt know how to format the response packet that could send a 404. And as for stopping the code from sending rubbish at the end of the packet, thats a logic error which i would have to see to correct.

Edit: Oh yea, and if the question is how to setup the packet, use telnet or ethereal and capture a 404 packet from a site.
__________________

tempest is offline   Reply With Quote
Old Nov 5th, 2004, 2:18 AM   #5
phrosys
Newbie
 
Join Date: Nov 2004
Posts: 24
Rep Power: 0 phrosys is on a distinguished road
a 404 is identical to any other response.

if we look at a HTTP response message:

----
{RESPONSE LINE}\r\n
{HEADERS}\r\n
\r\n
{MESSAGE}
----

where {RESPONSE LINE} is as follows:

{HTTP_VERSION} {STATUS_CODE} {STATUS_STRING}

The status code is used by the browser to determine the outcome of a request for example 200 for "OK" and 404 for "NOT FOUND", the status string is for the user.

When a user makes a request for a page that is valid, you will I am guessing be sending:


---
HTTP/1.1 200 OK\r\n
\r\n
{FILE CONTENT}
---

so finally we get to an error, when the page requested is not found:

---
HTTP/1.1 404 Not Found\r\n
\r\n
{ERROR PAGE}
---

when the file that the user is requesting is not available, you can switch to an error page and send that instead, the browser would still recognize it as an error!

hope it helps,

you don't need to capture packets thats a lil extreme for me anyway

-phrosys
phrosys is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC