Name

connectiondatasource (LzConnectionDatasource) (as2) — The connection datasource to receive and send messages through the persistent connection.

Synopsis

LZX: connectiondatasource
JavaScript: LzConnectionDatasource
Type: Class
Access: public
Runtimes: as2
Topic: LFC.Data
Declared in: WEB-INF/lps/lfc/data/platform/swf/LzConnectionDatasource.lzs

Description

Use the connectiondatasource tag to declare the datasets that handle will handle the incoming data from a connection. Unlike the connection tag, the connectiondatasource tag can be declared in libraries.

You can use the connection datasource to send messages and receive the list of connected users.

Example 5. Sending and receiving asynchronous messages

 <canvas debug="true" height="200" width="400">
   <debug y="60"/>
 
   <connection authenticator="anonymous">
     <handler name="onconnect">
       Debug.write("persistent connection established");
     </handler>
     <handler name="ondisconnect">
       Debug.write("persistent connection closed");
     </handler>
 
   </connection>
 
   <connectiondatasource name="mycd">
     <dataset name="dsetMessage" />
     <dataset name="dsetXML" />
   </connectiondatasource>
 
   <!-- Datapointer to listen for persistent connection messages -->
   <datapointer xpath="mycd:dsetMessage:/*[1]">
     <handler name="ondata">
       var from = this.xpathQuery('/from[0]/@name');
       var mesg = this.xpathQuery('/text()');
       Debug.write("got message (from " + from + "): '"+ mesg + "'");
     </handler>
   </datapointer>
 
   <!-- Datapointer to listen for persistent connection XML messages -->
   <datapointer xpath="mycd:dsetXML:/*[1]">
     <handler name="ondata">
       var mesg = this.xpathQuery('/myxml/text()');
       Debug.write("got xml mesg: '" + mesg + "'");
     </handler>
   </datapointer>
 
   <!-- Datapointer to listen for result of sendMessage call. -->
   <datapointer xpath="mycd:sendMessageDset:/*[1]">
     <handler name="ondata" args="d">
       Debug.write("d", d);
     </handler>
     <handler name="onerror" args="dset">
       Debug.write("error sending message: " + dset.errorstring);
     </handler>
 
   </datapointer>
 
   <!-- Datapointer to listen for result of sendXML call. -->
   <datapointer xpath="mycd:sendXMLDset:/*[1]">
     <handler name="ondata" args="d">
       Debug.write("d", d);
     </handler>
 
     <handler name="onerror" args="dset">
         Debug.write("error sending XML: " + dset.errorstring);
     </handler>
   </datapointer>
   
   <view x="10" y="10" layout="class: simplelayout; axis: x; spacing: 10">
     <button onclick="connection.connect()" text="connect" />
     <button onclick="connection.disconnect()" text="disconnect" />
 
     <button>send hello
       <handler name="onclick">
         mycd.sendMessage("*", "hello, world", "dsetMessage");
       </handler>
     </button>
 
     <button>send XML
       <handler name="onclick">
 
       <![CDATA[
           mycd.sendXML("*", "<myxml>hello, xml</myxml>", "dsetXML");
       ]]>
       </handler>
     </button>
   </view>
 </canvas>
 
 

See The Persistent Connection document for more information on the connection datasource and the persistent connection.

Sample-Apps

Sample applications that use the <connectiondatasource> tag are:

Superclass Chain

node (LzNode) » datasource (LzDatasource) » connectiondatasource (LzConnectionDatasource)

Known Subclasses

Details

Methods (12)

construct()
<method name="construct" args="parent, args" />
private function construct(parent, args);
doRequest()
<method name="doRequest" args="dset" />
private function doRequest(dset : LzDataset);
getList()
<method name="getList" args="users" />
public function getList(users : String);
Verify which users are connected. Result returned in the datasource's getListDset dataset.
getLoaderForDataset()
<method name="getLoaderForDataset" args="forset, proxied" />
public function getLoaderForDataset(forset, proxied);
getNewLoader()
<method name="getNewLoader" args="proxied" />
public function getNewLoader(proxied);
init()
<method name="init" />
private function init();
processRawData()
<method name="processRawData" args="dset, data" />
private function processRawData(dset, data);
Called by LzDataset.
sendAgentXML()
<method name="sendAgentXML" args="to, xml" />
public function sendAgentXML(to : String, xml : String);
Send arbitrary XML to agents only (no users). Result returned in the datasource's sendXMLDset dataset.
sendMessage()
<method name="sendMessage" args="to, mesg, dest" />
public function sendMessage(to : String, mesg : String, dest : String);
Send a message. The results are returned in the datasource's sendMessageDset dataset. The format of the message sent looks like: <pre> <from name="name" /> message </pre>
sendUserXML()
<method name="sendUserXML" args="to, xml, dest" />
public function sendUserXML(to : String, xml : String, dest : String);
Send arbitrary XML to users only (no agents). Result returned in the datasource's sendXMLDset dataset.
sendXML()
<method name="sendXML" args="to, xml, dest" />
public function sendXML(to : String, xml : String, dest : String);
Send arbitrary XML. Result returned in the datasource's sendXMLDset. The results are returned in the datasource's sendXMLDset dataset.
toString()
<method name="toString" />
private function toString() : String;
Get string representation of connection datasource.

LZX Synopsis

<class name="LzConnectionDatasource" extends=" LzDatasource ">
  <method name=" construct " args="parent, args" />
  <method name=" doRequest " args="dset" />
  <method name=" getList " args="users" />
  <method name=" getLoaderForDataset " args="forset, proxied" />
  <method name=" getNewLoader " args="proxied" />
  <method name=" init " />
  <method name=" processRawData " args="dset, data" />
  <method name=" sendAgentXML " args="to, xml" />
  <method name=" sendMessage " args="to, mesg, dest" />
  <method name=" sendUserXML " args="to, xml, dest" />
  <method name=" sendXML " args="to, xml, dest" />
  <method name=" toString " />
</class>

JavaScript Synopsis

public LzConnectionDatasource extends  LzDatasource  {
  prototype private function construct (parent, args);
  prototype private function doRequest (dset : LzDataset);
  prototype public function getList (users : String);
  prototype public function getLoaderForDataset (forset, proxied);
  prototype public function getNewLoader (proxied);
  prototype private function init ();
  prototype private function processRawData (dset, data);
  prototype public function sendAgentXML (to : String, xml : String);
  prototype public function sendMessage (to : String, mesg : String, dest : String);
  prototype public function sendUserXML (to : String, xml : String, dest : String);
  prototype public function sendXML (to : String, xml : String, dest : String);
  prototype private function toString () : String;
}