|
|||||||
| Development Tools and Practices Questions about development tools and practices. An appropriate place to talk about text editors, IDEs, and anything else that makes your development life easier. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
There seem to be a number of people looking to create a Persistent connection and while the laszlo documentation does contain documentation for persistent connections through the ConnectionManager class the developers guide says this class is "provisional" and "not recommended for deployment".
After some digging I found documentation for the XMLSocket class of the flash runtime, and have been able to create a working example using this as a basis for persistent connections. The documentation for this class is available on the Adobe Website. The following snippet shows a simple class creating such a socket and registering listeners for events. Code:
<class name="socket" extends="node"> <attribute name="xmlSocket" /> <handler name="oninit"> //SETUP A SOCKET xmlSocket = new XMLSocket(); //create a closure over 'this' var that = this; //CALLABCK FOR CONNECTING xmlSocket.onConnect = function () { that.onConnect.apply(that, arguments); }; //CALLBACK FOR REMOTE DISCONNECT xmlSocket.onClose = function () { that.onClose.apply(that, arguments); }; //CALLBACK FOR RECIEVED DATA xmlSocket.onData = function () { that.onData.apply(that, arguments); }; //SET THE LOCATION FOR THE CONNECTION POLICY System.security.loadPolicyFile("xmlsocket://myhost.com:2367"); </handler> ... </class> Using the socket is a fairly straightforward process using Code:
xmlSocket.connect("myhost.com", 3678);
Code:
xmlSocket.send(data);
Neither of the java examples provide appropriate error handling etc, and are provided as a simple means of showing "Hey, this does work!". That said any robust server can be used for the remote connection. A couple items of note. First as far as I can tell these sockets can only be used for character data since flash uses the byte 0x00 as a message terminator. Secondly I use the onData event in my processing, but the default is actually to parse the string into a flash XML object and pass this to a different handler "onXML". I don't know if the flash XML object is compatible/the same as the laszlo XML/dataset object but you can always use "LzDataNode.stringToLzData". In summary this provides a simple mechanism to create a raw socket between flash and some remote server. Since the socket is raw you may use any protocol you see fit, or pass XML and leverage Laszlo's capabilities to manipulate it. This persistent can be used to more easily create stateful applications. Finally this should make it possible to deploy applications SOLO where previously the LPS was necessary for "proxied only" features (such as JavaRPC in my case). I would be interested in knowing if anyone else has used this or another approach and what type of success/issues have been encountered. Last edited by mjessup; 07-22-2008 at 11:03 AM. Reason: Updated attached code for Laszlo 4.1.1 |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|