We do something similar with the remote debug protocol.
if you look at the file WEB-INF/lps/lfc/debugger/platform/swf/LzRemote.as
you will see the usage
of the Flash APIs. They can be accessed as normal Javascript for the most
part.
For example the code to open and send a message looks like
Debug.sockOpen = function (port) {
var url = LzBrowser.getLoadURLAsLzURL();
// Security requires us to talk back to the server we were loaded from
var host = url.host;
this.xsock = new XMLSocket();
this.xsock.onClose = this.brokensocket;
this.xsock.onXML = this.socketXMLAvailable;
if (! this.xsock.connect(host, port)) {
Debug.log("remote debugger could not connect to listener " + host + ":"
+ port);
}
this.writeInitMessage();
}
/**
* @access private
*/
Debug.writeInitMessage = function () {
var filename = LzBrowser.getLoadURLAsLzURL();
var myXML = new XML();
var init = myXML.createElement("init");
myXML.appendChild(init);
init.attributes.filename = filename;
init.attributes.language = "LZX";
init.attributes.protocol_version = "1.0";
init.attributes.build = canvas.lpsbuild;
init.attributes.lpsversion = canvas.lpsversion;
init.attributes.lpsrelease = canvas.lpsrelease;
init.attributes.runtime = canvas.runtime;
init.attributes.appid = "0";
this.xsock.send(myXML);
}
and the code to hook into the callback for received XML looks like
Debug.socketXMLAvailable = function (doc) {
var e = doc.firstChild;
var rloader = Debug.rdbloader;
if (e != null) {
// clear warnings history
Debug.resetWarningHistory();
Debug.inEvalRequest = true;
var seqnum = e.attributes['seq'];
if (seqnum == null) {
seqnum = Debug.seqnum++;
}
if (e.nodeName == "exec") {
var expr = e.firstChild.nodeValue;
rloader.request( { lz_load : false,
lzt : "eval",
proxied: true,
lzrdbseq : seqnum,
lz_script : "#file evalString\n#line 0\n" + expr
} );
} else if (e.nodeName == "eval") {
var expr = e.firstChild.nodeValue;
rloader.request( { lz_load : false,
lzt : "eval",
proxied: true,
lzrdbseq : seqnum,
lz_script : "#file evalString\n#line 0\n" +
expr } );
} else if (e.nodeName == "inspect") {
Debug.inEvalRequest = false;
var id = e.attributes.id;
Debug.sockWriteAsXML(Debug.ObjectForID(id), seqnum);
} else {
Debug.inEvalRequest = false;
Debug.sockWrite("<response seq='"+seqnum+"'><error msg='unknown
remote debug command'>"+e.nodeName+"</error></response>");
}
} else {
Debug.inEvalRequest = false;
Debug.sockWrite("<response seq='-1'><error msg='null remote debug
command'/></response>");
}
}
You may want to put some of that code into a <script when="immediate"> block
On Thu, May 8, 2008 at 9:30 AM, Evaldas Taroza <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Thanks Henry for the pointer. Indeed I need a TCP socket. Normal Dataset
> will not do the job, I think.
>
> When you say to use Flash API, how do I do it? I mean, in Flash I suppose
> there is another programing language, like ActionScript, so how do I do it
> from within OL then?
>
> And when you say that Flash API is not officially supported by OL can it be
> that my app will eventually break, when you change somethings inside OL?
>
> A bit about my problems:
> As I told you I am taking my first steps with OL. So I decided to write
> some simple chat program, which would support a very small subset of XMPP.
> So as a start I need to send to the chat server the following text:
> <?xml version='1.0' encoding='UTF-8'?>
> <stream:stream
> to='localhost'
> xmlns='jabber:client'
> xmlns:stream='http://etherx.jabber.org/streams'
> version='1.0'>
>
> And the server responds to something similar as well. As you can see it is
> not a well-formed XML document, so I need to treat it as text and parse it.
> All the subsequent communication happens with well-formed XML snippets.
>
> Do you think it's possible?
>
> Evaldas
>
> Henry Minsky wrote:
>
>> For streaming I/O to a TCP socket, if you restrict your self to the Flash
>> runtime, you can use the Flash XMLSocket API , which has some restrictions,
>> such as it must use TCP ports above 1024 I think.
>>
>> The API can be found in the Flash reference manual, it is not officially a
>> supported API in OpelLaszlo though.
>>
>> We used this API for one of the remote debugger protocols at one point.
>> There is still some code in the debugger implementation for it I think,
>> which could be used as an example.
>>
>>
>> On Thu, May 8, 2008 at 12:35 AM, Evaldas Taroza <[EMAIL PROTECTED]<mailto:
>> [EMAIL PROTECTED]>> wrote:
>>
>> Dear OL users,
>>
>> I am pretty new to OL. What I am trying to achieve is to open a
>> socket to a host (crossdomain) and read incoming textual data.
>>
>> Incoming data will most likely be an XML document, but I don't want
>> to read the whole document, I rather need to deal with it as it
>> comes, in a streaming manner. How can I achieve this?
>>
>> Thank you very much for help!
>>
>> Evaldas
>>
>> -- +41 79 616 53 76
>> www.linkedin.com/in/taroza <http://www.linkedin.com/in/taroza>
>>
>> Optaros - www.optaros.com <http://www.optaros.com>
>>
>>
>>
>>
>> --
>> Henry Minsky
>> Software Architect
>> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>>
>>
>
>
> --
> +41 79 616 53 76
> www.linkedin.com/in/taroza
>
> Optaros - www.optaros.com
>
>
--
Henry Minsky
Software Architect
[EMAIL PROTECTED]