HTTP Stream SessionID

BlitzMax Forums/BlitzMax Beginners Area/HTTP Stream SessionID

Rambo_Bill(Posted 2005) [#1]
I've created this bit of code:


Which works, but each time I make a request I get a new sessionID.. How Do I maintain a session, thus keeping the same sessionID?

Okay, I've come up with a more elaborate way that I'd think would keep the same connection thus keeping the same session id, but still no luck. Also the timing is buggy. Apologize for the sloppy code, I haven't cleaned it up yet.



*Edit cleaned up second example a little more.


Rambo_Bill(Posted 2005) [#2]
Figured it out, you have to store the cookie it sends you and send it back each additional request. Wish the freaking HTTP 1.1 Docs said something about the cookie. Anyway, Once I clean it up I'll probably post the code. Sessions rock. What would be awsome is if there would be someway that blitz streams could do this all automatically, but I doubt that would very important to anyone but me.


Rambo_Bill(Posted 2005) [#3]
Okay dealing with ReadLine was buggy, sometimes when you call it, it just sits, sometimes it returns "0", and eof for stream is never set. I think Readline should just return an empty string if nothing is available. Anyways, this code works:



skidracer(Posted 2005) [#4]
The http/1.1 protocol sends a byte count which could be used to create a bank stream buffer (read the reply into a bank) which will give you a usable eof() which raw streams obviously can't provide given 1.1 connections are left open by the server.


Rambo_Bill(Posted 2005) [#5]
It's a byte count of the content, but does not include the HTTP header. So how do I know when the header ends unless I assume an <html> tag?


skidracer(Posted 2005) [#6]
From memory a blank line marks the end of the header.


Rambo_Bill(Posted 2005) [#7]
Then I have to assume ReadLine is returning nothing because its a new line, not sure that is safe to do. I could test it more. But sounds like a good idea.


Perturbatio(Posted 2005) [#8]
is it not two newline characters for the end of a header?


Rambo_Bill(Posted 2005) [#9]
I'm only getting one, but I think it's probably the best way to go. Get the content length from the header designated by a empty new line (readline returns nothing). Then read the content length in or hit a timeout.. I'll recode it tommorrow night after work.


Perturbatio(Posted 2005) [#10]
I only mentioned it since it's what I do with the cgi apps I've written. And in the CGI module I wrote, PrintHTMLHeader does:
Print "Content-type:  text/html~n~n"



Rambo_Bill(Posted 2005) [#11]
Well, I rewrote it to use the length. Works with my host because thier servers send Content-Length: xxx, but yahoo,google, BlitzMAx all appear to be using another method (Chunking) which I'm not interested in as I just need it to work with my site.