[REBOL] Re: Problems rendering an image + jpeg images not working
From: brett:codeconscious at: 30-Aug-2002 22:02
> If there are any further questions, I would be happy to shed further
> confusion. ;-)
My turn... :^)
I believe the objective is to "stream" a series of images to the browser
from a server (original source a web cam).
The multipart/x-mixed-replace is a way to deliver to the browser multiple
versions of the "same" image so that the browser should replace the image
when it receives the next part in the multipart stream.
IE apparently does not support this, for IE a activex object in the HTML
page must be used. Theoretically "other" browsers might support it directly.
My experience with Netscape so far shows promis because it does correctly
finish with the final image, but does not show the earlier images. Netscape
appears to be waiting until the connection is closed.
The problem I think is that my REBOL script does not send any data to the
browser until it quits. I've tried setting the mode of the output port to
no-wait, but no change. Can someone solve this?
Anyway, Tim, you'll probably have the ActiveX so this script might help you
out by having something to compare with.
I'm using three small gifs, but the principal should be the same as for the
web cam.
Things to watch:
(1) Line endings. Note how I've set binary mode on for all my output.
Therefore I need to supply the network standard line ending of CRLF.
(2) Line endings again. Number of line endings between headers and content.
Here's my work so far:
--8<----- The HTML page ---------------------
<html>
<body>
<h1>multipart/x-mixed-replace</h1>
<center>
<img border="1"
src="http://localhost/cgi-bin/pushtest.r.cgi"
height="37" width="37" alt="Streamed Image">
</center>
</body>
</html>
--8<----- The CGI script ---------------------
#!E:/Downloads/Languages/Rebol/Experimental/core2503031 -cs
REBOL [
Title: {Server Push CGI Test}
Author: {Brett Handley}
Date: 29-Aug-2002
Comment: {
See http://wp.netscape.com/assist/net_sites/pushpull.html
}
]
if error? err: try [
boundary-string: "ThisRandomString"
boundary: rejoin [CRLF {--} boundary-string]
emit: func [data] [
if block? data [data: rejoin data]
insert system/ports/output data
insert system/ports/output CRLF
]
set-modes system/ports/output [binary: true]
emit [
{Content-Type: multipart/x-mixed-replace;}
{ boundary-string="} boundary-string {"}
]
emit boundary
repeat i 3 [
file-data: read/binary file: join %n [i %.gif]
emit {Content-Type: text/gif}
emit {}
emit file-data
emit boundary
write/append %pushtest.log join form now [
" " file " " length? file-data newline
]
wait 00:00:01
]
] [write/append %pushtest.log join form now [mold disarm err newline]]
QUIT
--8<----- Little script to test CGI ---------------------
p: open/direct/binary/no-wait http://localhost/cgi-bin/pushtest.r.cgi
until [
wait p
none? if not none? s: copy p [print length? s]
]
close p
--8<----- %n1.gif ---------------------
#{
47494638396125002500B30000FFFFFF0000008A8A8A454545111111EFEFEF55
55559A9A9AAAAAAABBBBBB666666DFDFDF212121CFCFCF31313176767621F904
00000000002C000000002500250000048B10C849ABBD38EBCDBBFF5C21086089
104190945D61A4A9C16E0D03A7C39C1DE81DE43ACBC30753042D30870F71AC04
1808C18DD1BC2C7C87AA45712314B494868F049E0CBADF3220E133AA01AFDBE2
7DBD01D5DC1BF3DD4B51DF07636F703E737C37326F6C37596F5237696A713883
006730646F97292B83083799803DA16F22029D95A9AAABACADAE0011003B
}
--8<----- %n2.gif ---------------------
#{
47494638396125002500B30000FFFFFF0000008A8A8A454545111111EFEFEF9A
9A9A555555CFCFCFBBBBBB767676212121AAAAAADFDFDF31313166666621F904
00000000002C00000000250025000004CD10C849ABBD38EBCDBBFF60E8218670
0CE8538856611C4420CFF2C34E8512D37C40DC8082A3470C246E8A6260A038CC
04ACC28EF660501632A8C84023085614C693E5940D1A16C4D4C09A061C07C4C4
E0468B88D04679666BFB0E02090505023D0E604073583C8789130903442A8E41
493D045694088B3C0A88895C3D0B479400A13C5AA5A7330372A500093C5EAF12
059C4B768F02286C228532B3B0060A9134A920C50127434A9921C94A330B48D1
5DAE2208D5320BD72CD0B207BD8E0C02E5E50609B9B4EBECEDEEEFF0EB11003B
}
--8<----- %n3.gif ---------------------
#{
47494638396125002500B30000FFFFFF0000008A8A8A454545111111CFCFCF55
5555666666BBBBBB2121219A9A9AEFEFEFDFDFDF313131AAAAAA76767621F904
00000000002C00000000250025000004CF10C849ABBD38EBCDBBFF60D82D8822
9CA7C388167224412CCF43C102C530EF3B618705026F2833880EC3C600F59211
443AD9008131C844D6D901D3B8020760F0B6B2C8068C374CE1219451D31386A3
B953A40B8AC7A0CD33FC440E7C3C04060A0B70303B09070A7F7008440906022B
70000244330F96980D9327077B349619085D318EA4140E3202AA1766AE210C6F
18653376200FA8170B028204871F980104B5000C0A483CB21F8209609901631F
90D23CD41F0CD733040E37C4D20902C2372EA7329E02A9AFEDEEEFF0F1F2F211
003B
}
---
Website: http://www.codeconscious.com
Rebsite: http://www.codeconscious.com/index.r