Valhalla Legends Forums Archive | General Programming | Sreaming Http Content

AuthorMessageTime
iago
I'm trying to write something similar to Skywing's ISAPI for streaming Battle.net channels, but I'm having a problem with getting it to work on all browsers.

Here is what I'm sending now:
[code]
    out.write(protocol + " 200 OK\n");
    out.write("Connection: close\n");
    out.write("Date: " + new Date() + "\n");
    out.write("Server: TestServer\n");
    out.write("Pragma: no-cache\n");
    out.write("Cache-Control: no-cache\n");
    out.write("Content-type: text/html\n");
    out.write("\n");
    out.flush();
[/code]
Followed by the streaming HTML as it comes.

I think this is the same as Skywing's, but since it's not working 100%, I guess it's not.  Is there some special way to tell the browser there's going to be a stream coming or something?

Thanks!
September 29, 2004, 1:22 PM
Soul Taker
I think the trick is telling the browser that the HTML you're sending is humongous, that way it will keep  waiting for more data.  Then you just send the new stuff as it comes.
September 29, 2004, 3:38 PM
TangoFour
Instead of \n, shouldn't you use \r\n ? Carriage Return, followed by Line Feed?

I think I read something about it in the HTTP RFC
September 29, 2004, 3:45 PM
Skywing
[quote author=Soul Taker link=topic=8939.msg82608#msg82608 date=1096472316]
I think the trick is telling the browser that the HTML you're sending is humongous, that way it will keep  waiting for more data.  Then you just send the new stuff as it comes.
[/quote]
No, then the browser will tend to not show the page until all the HTML is loaded (at leastt Netscape works like this, IIRC -- IE eventually starts showing stuff, but it takes time).  Regardless, not a desireable solution.

[quote author=TangoFour link=topic=8939.msg82610#msg82610 date=1096472704]
Instead of \n, shouldn't you use \r\n ? Carriage Return, followed by Line Feed?

I think I read something about it in the HTTP RFC
[/quote]

Yes, it should be \r\n over the network (though perhaps iago's CGI interface is automagically translating \n into \r\n -- he needs to check on this, though).

The way I do it is like this:

[code] if(!Streaming)
wsprintf(ContentLength+strlen(ContentLength), "Content-Length: %u\r\n\r\n", Bytes);
else
strcat(ContentLength, "\r\n");[/code]
September 29, 2004, 6:03 PM
iago
No, I wasn't sending \r\n.  I'll try doing that instead and see if it improves the performance in some browsers.
September 29, 2004, 10:51 PM
Myndfyr
I agree with Tango and Skywing: generally, you need to use \r\n.  

The way to keep the browser streaming is to completely emit the

[code]
Content-Length:
[/code]

from the HTTP header.

That should keep the socket alive on both ends.

Although -- from Skywing's code it looks like he uses Content-Length: \r\n\r\n and just doesn't specify a length.  From having packet-sniffed your headers, though, I don't recall seeing Content-Length at all.
September 29, 2004, 10:52 PM
St0rm.iD
This seems like a web development topic to me :)
September 30, 2004, 12:02 AM
K
[quote]
Although -- from Skywing's code it looks like he uses Content-Length: \r\n\r\n and just doesn't specify a length.  From having packet-sniffed your headers, though, I don't recall seeing Content-Length at all.
[/quote]

Look at what is written to the variable ContentLength in the first case vs. the second case.
September 30, 2004, 12:02 AM
Myndfyr
[quote author=K link=topic=8939.msg82670#msg82670 date=1096502550]
[quote]
Although -- from Skywing's code it looks like he uses Content-Length: \r\n\r\n and just doesn't specify a length.  From having packet-sniffed your headers, though, I don't recall seeing Content-Length at all.
[/quote]

Look at what is written to the variable ContentLength in the first case vs. the second case.
[/quote]

Ahhh my mistake, he's not actually writing "Content-Length", he's writing *to* ContentLength.  ;)
September 30, 2004, 12:58 AM
iago
[quote author=$t0rm link=topic=8939.msg82669#msg82669 date=1096502532]
This seems like a web development topic to me :)
[/quote]

I'd say this suits Bot Development, because this is part of my bot :P

But I don't read the web development board, and I know that a lot of people don't, so posting it here it was more likely that I'd get a response, and also more likely that I'd remember its existance.

It helps, too, that I moderate this board :)

The problem I was having is that some browsers (Safari, IE, and some others) weren't displaying the page until the socket was closed (by me exiting).  Hopefully that'll change when I do \r\n.
September 30, 2004, 2:05 AM
Skywing
You're required to use \r\n by the HTTP spec, so it wouldn't surprise me if failing to do so is causing browsers to act strangely.
September 30, 2004, 7:26 PM
iago
Hmm, I made it \r\n and I still have the problem.  The weird thing is, my headers are the same as Skywing's, but his works with the browser and mine doesn't :(

I'm going to have to research this problem more, I guess :/
September 30, 2004, 11:19 PM
St0rm.iD
What language/framework/library are you running on?
October 1, 2004, 12:40 AM
Myndfyr
[quote author=iago link=topic=8939.msg82769#msg82769 date=1096586393]
Hmm, I made it \r\n and I still have the problem.  The weird thing is, my headers are the same as Skywing's, but his works with the browser and mine doesn't :(

I'm going to have to research this problem more, I guess :/

[/quote]

Are you using a pure socket connection (Java), and is your socket staying connected when streaming?
October 1, 2004, 1:53 AM
iago
Storm -- it doesn't matter.  I'm using Java with a plain BufferedOutputStream.

Mynd - yes.  The problem is that at least one browser (Safari) doesn't recognize the streaming content until the socket is closed.  Once I close it, it displays the entire thing.

I would assume it's a problem with the browser, but he said he can see Webbot streams fine.
October 1, 2004, 12:29 PM
St0rm.iD
Are you sure you're calling flush()?
October 2, 2004, 2:50 AM
iago
Yes.  If i wasn't, it wouldn't work on other browsers.  The information is defintaely getting there.
October 2, 2004, 6:17 AM

Search