404 Headers Help

Everything else that doesn't fall into one of the other PB categories.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

404 Headers Help

Post by Killswitch »

Hi,

I'm in the process of writing KNet v2.0 - a webserver. The original incarnations (v1.0-1.04c) were based around the Atomic Webserver example. I've decided to pull away from this and start afresh, but I have been using some of the methods Atomic uses.

I wanted to include 404 headers, but whenever I try to send one my browser just hangs and doesn't come up with a 404 header. Sometimes I get a 'an attempted read to/write to error from which that process isn't allowed' error.

Here's my header:

Code: Select all

Procedure.l Build404Header(*Buffer)
      
Length = PokeS(*Buffer,"HTTP/1.1 404 Not Found"+EOL$)        *Buffer+Length
 Length = PokeS(*Buffer,"Server: "+#Server+" "+#Version+EOL$) *Buffer+Length  
;Date.s=CurrentDate() Need my fuction for that - takes up a lot of room
Length = PokeS(*Buffer,"Date: "+Date+EOL$)
*Buffer+Length 
Length = PokeS(*Buffer,"Content-Length: 0"+EOL$)                    : *Buffer+Length  
Length = PokeS(*Buffer,"Content-Type: text/html"+EOL$)              : *Buffer+Length                                    
Length = PokeS(*Buffer, EOL$)                                       : *Buffer+Length     
      ProcedureReturn *Buffer
EndProcedure


And here's the code I'm sending it with:

Code: Select all

*Header404=AllocateMemory(500)
*HeaderOffset=Build404Header(*Header404)
SendNetworkData(ID,*Header404,*HeaderOffset)
FreeMemory(*Header404)
Thanks for the help,

(I'll be relasing the full source once it works :D)
~I see one problem with your reasoning: the fact is thats not a chicken~
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

The third parameter to SendNetworkData() is the length of the buffer. You're not passing that, you need to use *HeaderOffset-*Header404.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

You should be carefull with what you try to send ;)
Maybe doing it like this will help with your read/writte access error:

Code: Select all

 ...
SendNetworkData(ID,*Header404,*HeaderOffset-*Header404)
 ...
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Thanks,

There's no error now, but IE still hangs - until I close the server then the 404 page pops up. Pretty strange isn't it?
~I see one problem with your reasoning: the fact is thats not a chicken~
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

How have you defined EOL$?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Global Variable, I tried a constant but that didn't seem to work at all.
~I see one problem with your reasoning: the fact is thats not a chicken~
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Are you closing the connection to the client after header is sent?
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Nope, how can I do that?
~I see one problem with your reasoning: the fact is thats not a chicken~
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Killswitch wrote:Nope, how can I do that?
Have you read the manual? ;)

I think 'CloseNetworkConnection(ID)' will do just fine :)
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Problem still persists, its really strange.
~I see one problem with your reasoning: the fact is thats not a chicken~
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Killswitch wrote:Problem still persists, its really strange.
I just noticed this:

Code: Select all

Length = PokeS(*Buffer,"HTTP/1.1 404 Not Found"+EOL$)        *Buffer+Length
 Length = PokeS(*Buffer,"Server: "+#Server+" "+#Version+EOL$) *Buffer+Length  
You see something wrong with those two lines? Well you should as they're missing the expression separator ':', which means that you basicly multiply the result of Pokes() with the undefined variable 'buffer'! The result is a messed up header that is missing vital stuff..
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

Ah, thats the reult of a dodgey copy+paste job - the colons are there in my actual code.

Edit:

I don't really know how I did it, but the code is working now! Expect a realse really soon.
~I see one problem with your reasoning: the fact is thats not a chicken~
Post Reply