Name
connection (LzConnection) (as2) — A connection manager to create a persistent connection and an
authenticated session.
Description
The connection
tag instantiates a connection
manager object that handles asynchronous messages sent from the OpenLaszlo
Server. Use the the LzConnection.connect
method to establish a
persistent connection and disconnect
to close it down.
Example 3. Connection example
<canvas debug="true" height="200">
<debug y="60"/>
<connection authenticator="anonymous">
<handler name="onconnect">
Debug.write('connected');
</handler>
<handler name="ondisconnect">
Debug.write('client disconnected');
</handler>
</connection>
<view>
<simplelayout axis="x" spacing="5"/>
<button>connect
<handler name="onclick">
canvas.connection.connect();
</handler>
</button>
<button>disconnect
<handler name="onclick">
canvas.connection.disconnect();
</handler>
</button>
</view>
</canvas>
You can optionally use the clientDisconnect
method to close
down only the client-side connection. The server will drop its end of the
connection when it next becomes aware that the connection has been dropped.
The previous example declares connection
with
authenticator="anonymous"
, which tells the connection
manager that no authentication should be used to handle the persistent
connection. Normally, the connection manager will tell the OpenLaszlo Server to
verify that your connection is authenticated with a back-end
authentication server before allowing the persistent connection, which
is done through a session cookie. The default authentication server it
uses is the AuthenticationServlet
bundled with the OpenLaszlo Server. The set of usernames that server uses is located in
lps/config/lzusers.xml
. To session and unsession your
application, use the connection's login
and
logout
methods.
The next example demonstrates how to login with the username
adam
. Note that you will be allowed to connect only after
logging in.
Example 4. Session Example
<canvas debug="true" height="200">
<debug y="60"/>
<connection>
<handler name="onconnect">
Debug.write('connected as ' + connection.getUsername());
</handler>
<handler name="ondisconnect">
Debug.write('client disconnected');
</handler>
</connection>
<datapointer xpath="connection:loginDset:/login[1]/authentication[1]/response[1]/status[1]">
<handler name="ondata">
var statusMessage = this.xpathQuery('@msg');
Debug.write('login: ' + statusMessage);
</handler>
<handler name="onerror">
Debug.write('login resulted in error');
</handler>
<handler name="ontimeout">
Debug.write('login timed out');
</handler>
</datapointer>
<datapointer xpath="connection:logoutDset:/logout[1]/authentication[1]/response[1]/status[1]">
<handler name="ondata">
var statusMessage = this.xpathQuery('@msg');
Debug.write('logout: ' + statusMessage);
</handler>
<handler name="onerror">
Debug.write('logout resulted in error');
</handler>
<handler name="ontimeout">
Debug.write('logout timed out');
</handler>
</datapointer>
<view>
<simplelayout axis="x" spacing="5"/>
<button>login
<handler name="onclick">
canvas.connection.login('adam', 'adam');
</handler>
</button>
<button>logout
<handler name="onclick">
canvas.connection.logout();
</handler>
</button>
<simplelayout axis="x" spacing="5"/>
<button>connect
<handler name="onclick">
canvas.connection.connect();
</handler>
</button>
<button>disconnect
<handler name="onclick">
canvas.connection.disconnect();
</handler>
</button>
</view>
</canvas>
Once a connection is established, clients can send and receive messages
using the connectiondatasource
tag.
Sample Apps
Sample applications that use the connection
tag are:
Development Note
LzConnection multiplexes all incoming data from a persistent connection into
a connection datasource's dataset (see LzConnectionDatasource).
Details
Initial Attributes (7)
Initial Attributes are given as attributes in LZX but are not generally available as properties in JavaScript.
-
authenticator
-
<attribute name="authenticator" />
-
authparam
-
<attribute name="authparam" />
-
group
-
<attribute name="group" />
-
heartbeat
-
<attribute name="heartbeat" type="number" />
-
secure
-
<attribute name="secure" />
-
secureport
-
<attribute name="secureport" />
-
timeout
-
<attribute name="timeout" type="number" />
Properties (1)
-
LzAgent()
-
<method name="LzAgent" />
private function LzAgent();
LzAgent is a placeholder to silence warnings about undefined
classes -- the tag is permitted in a connection but only used
on the server side
Setters (1)
Setters for virtual properties, to be used with setAttribute. A setter may or may not have a corresponding getter method;
consult the Methods list in this section.
-
authparam
Methods (32)
-
clientDisconnect()
-
<method name="clientDisconnect" />
public function clientDisconnect();
Disconnect connection, but don't notify server. See disconnect().
-
connect()
-
<method name="connect" />
public function connect();
Establish a connection. An application typically must be sessioned before
calling this method.
-
construct()
-
<method name="construct" args="parent, args" />
private function construct(parent, args);
-
disconnect()
-
<method name="disconnect" />
public function disconnect();
Disconnect connection. This also notifies the server to disconnect the
application. The results from asking the server to disconnect are returned in
the connection's disconnectDset. See clientDisconnect().
-
doRequest()
-
<method name="doRequest" args="dset" />
private function doRequest(dset : LzDataset);
-
getAuthParam()
-
<method name="getAuthParam" />
public function getAuthParam() : String;
Get parameters for authenticator.
-
getLoaderForDataset()
-
<method name="getLoaderForDataset" args="forset, proxied" />
public function getLoaderForDataset(forset, proxied);
-
getNewLoader()
-
<method name="getNewLoader" args="proxied" />
private function getNewLoader(proxied) : LzLoader;
This is a helper method to create a loader for the dataset.
-
getSID()
-
public function getSID() : String;
Get connection's session id.
-
getUsername()
-
<method name="getUsername" />
public function getUsername() : String;
Get connection's username.
-
init()
-
-
login()
-
<method name="login" args="usr, pwd" />
public function login(usr : String, pwd : String);
Authenticate and session the application. The results from this call are
returned in the connection's loginDset.
-
logout()
-
public function logout();
De-authenticate and unsession the application. The results from this call are
returned in the connection's logoutDset.
-
__LZconnect()
-
<method name="__LZconnect" args="type" />
private function __LZconnect(type);
-
__LZdisconnect()
-
<method name="__LZdisconnect" />
private function __LZdisconnect();
Close down the connection.
-
__LZgetList()
-
<method name="__LZgetList" args="users, result" />
private function __LZgetList(users : String, result : LzDataset);
Verify which users are connected. Result returned in LzConnection.getListDset
dataset.
-
__LZgotData()
-
<method name="__LZgotData" args="data" />
private function __LZgotData(data);
This function makes sure the connection message gets delivered to the
right dataset.
-
__LZgotError()
-
<method name="__LZgotError" args="error" />
private function __LZgotError(error);
-
__LZgotTimeout()
-
<method name="__LZgotTimeout" />
private function __LZgotTimeout();
-
__LZreconnect()
-
<method name="__LZreconnect" />
private function __LZreconnect();
-
__LZreconnect1()
-
<method name="__LZreconnect1" />
private function __LZreconnect1();
-
__LZregisterDatasource()
-
<method name="__LZregisterDatasource" args="dsrc" />
private function __LZregisterDatasource(dsrc);
-
__LZsendAgentXML()
-
<method name="__LZsendAgentXML" args="to, xml, result" />
private function __LZsendAgentXML(to : String, xml : String, result : LzDataset);
Send arbitrary XML to agents only (no users). Result returned in
LzConnection.sendXMLDset.
-
__LZsendEvent()
-
<method name="__LZsendEvent" args="event, obj" />
private function __LZsendEvent(event, obj);
-
__LZsendMessage()
-
<method name="__LZsendMessage" args="to, mesg, dest, result" />
private function __LZsendMessage(to : String, mesg : String, dest : String, result : LzDataset);
Send a message. The format of the message sent looks like:
<from></from>
message
The results are returned in the connection's sendMessageDset dataset.
-
__LZsendUserXML()
-
<method name="__LZsendUserXML" args="to, xml, dest, result" />
private function __LZsendUserXML(to : String, xml : String, dest : String, result : LzDataset);
Send arbitrary XML to users only (no agents). Result returned in
LzConnection.sendXMLDset.
-
__LZsendXML()
-
<method name="__LZsendXML" args="to, xml, dest, result" />
private function __LZsendXML(to : String, xml : String, dest : String, result : LzDataset);
Send arbitrary XML. Result returned in
LzConnection.sendXMLDset.
-
__LZunloadConnection()
-
<method name="__LZunloadConnection" />
private function __LZunloadConnection();
-
__LZunloadConnection1()
-
<method name="__LZunloadConnection1" />
private function __LZunloadConnection1();
-
processRawData()
-
<method name="processRawData" args="dset, data" />
private function processRawData(dset, data);
-
setAuthParam()
-
<method name="setAuthParam" args="authparam" />
public function setAuthParam(authparam : String);
Set paramaters for server authenticator.
-
toString()
-
<method name="toString" />
private function toString();
LZX Synopsis
<class name="
LzConnection" extends="
LzHTTPDatasource
">
<method name="
construct
" args="
parent,
args" />
<method name="
login
" args="
usr,
pwd" />
<method name="
__LZsendXML
" args="
to,
xml,
dest,
result" />
</class>
JavaScript Synopsis
public
LzConnection extends
LzHTTPDatasource
{
prototype public function
connect
();
prototype private function
construct
(
parent,
args);
prototype private function
doRequest
(
dset : LzDataset);
prototype private function
getNewLoader
(
proxied) :
LzLoader;
prototype public function
getSID
() :
String;
prototype private function
init
();
prototype public function
login
(
usr : String,
pwd : String);
prototype public function
logout
();
prototype private function
__LZgetList
(
users : String,
result : LzDataset);
prototype private function
__LZsendAgentXML
(
to : String,
xml : String,
result : LzDataset);
prototype private function
__LZsendMessage
(
to : String,
mesg : String,
dest : String,
result : LzDataset);
prototype private function
__LZsendUserXML
(
to : String,
xml : String,
dest : String,
result : LzDataset);
prototype private function
__LZsendXML
(
to : String,
xml : String,
dest : String,
result : LzDataset);
prototype public function
setAuthParam
(
authparam : String);
}