Page 1 of 1

404 Headers Help

Posted: Mon May 02, 2005 8:27 pm
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)

Posted: Mon May 02, 2005 8:38 pm
by tinman
The third parameter to SendNetworkData() is the length of the buffer. You're not passing that, you need to use *HeaderOffset-*Header404.

Posted: Mon May 02, 2005 8:39 pm
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)
 ...

Posted: Mon May 02, 2005 9:13 pm
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?

Posted: Mon May 02, 2005 9:23 pm
by tinman
How have you defined EOL$?

Posted: Mon May 02, 2005 9:24 pm
by Killswitch
Global Variable, I tried a constant but that didn't seem to work at all.

Posted: Mon May 02, 2005 9:36 pm
by Pupil
Are you closing the connection to the client after header is sent?

Posted: Mon May 02, 2005 10:01 pm
by Killswitch
Nope, how can I do that?

Posted: Mon May 02, 2005 10:41 pm
by Pupil
Killswitch wrote:Nope, how can I do that?
Have you read the manual? ;)

I think 'CloseNetworkConnection(ID)' will do just fine :)

Posted: Wed May 04, 2005 7:26 pm
by Killswitch
Problem still persists, its really strange.

Posted: Wed May 04, 2005 11:46 pm
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..

Posted: Thu May 05, 2005 9:01 am
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.