• Welcome to Valhalla Legends Archive.
 

Sreaming Http Content

Started by iago, September 29, 2004, 08:22 AM

Previous topic - Next topic

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:

    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!
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


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.

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

Skywing

#3
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");

iago

No, I wasn't sending \r\n.  I'll try doing that instead and see if it improves the performance in some browsers.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna

This seems like a web development topic to me :)

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.

Look at what is written to the variable ContentLength in the first case vs. the second case.

MyndFyre

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.  ;)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

iago

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


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.

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 :/
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Banana fanna fo fanna

What language/framework/library are you running on?

MyndFyre

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?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*