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:
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();
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!
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.
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 from: Soul Taker on September 29, 2004, 10:38 AM
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.
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 from: TangoFour on September 29, 2004, 10:45 AM
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
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:
if(!Streaming)
wsprintf(ContentLength+strlen(ContentLength), "Content-Length: %u\r\n\r\n", Bytes);
else
strcat(ContentLength, "\r\n");
No, I wasn't sending \r\n. I'll try doing that instead and see if it improves the performance in some browsers.
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
Content-Length:
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.
This seems like a web development topic to me :)
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.
Look at what is written to the variable ContentLength in the first case vs. the second case.
Quote from: K on September 29, 2004, 07:02 PM
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.
Look at what is written to the variable ContentLength in the first case vs. the second case.
Ahhh my mistake, he's not actually writing "Content-Length", he's writing *to* ContentLength. ;)
Quote from: $t0rm on September 29, 2004, 07:02 PM
This seems like a web development topic to me :)
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.
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.
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 :/
What language/framework/library are you running on?
Quote from: iago on September 30, 2004, 06:19 PM
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 :/
Are you using a pure socket connection (Java), and is your socket staying connected when streaming?
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.
Are you sure you're calling flush()?
Yes. If i wasn't, it wouldn't work on other browsers. The information is defintaely getting there.