Make your own free website on Tripod.com

Tutorial on Laszlo Presentation Server (LPS) Persistant Connection and backend Agent

by Jack Hung Version:1.0 10/24/2004


Laszlo is an open source platform for the development and delivery of rich Internet applications on the World Wide Web.

Note: the binary distribution LPS-2.2 has a bug with the Agent code. I've submitted a patch to the forum ( see link). You need to apply the patch or grab my patched jar here.

The Application - a Stock Quote Server pushing stock price to a LPS client application(lzx)

You can find the application's source here. You are suppose to extract the files in the directory ${LPS_HOME}/Server/lps-2.2/examples. That will create two directories: quoteAgent and quoteServer.

Once you have the files in place, point your browser to your local version of this page by pointing your browser to "http://localhost:8080/lps/examples/quoteAgent/main.html". Then follow the steps below.

Step:
  1. The Application UI (view source)

    First here is the simple client application. Here, I just use a local dataset sampledataset.lzx to try out the UI.

  2. Connection to LPS Agent (Proxy) (view source)

    What I've done here is to wrap the dataset within a connectiondatasource and create a connection specifying an agent. Note that the actuall url of the agent is not important at this point. What we are doing here is to make sure we can connect to the LPS with a persistant connection.

    
      <connection authenticator="anonymous" group="client">
    	  <agent url="http://localhost:8080/lps/examples/quoteServer/somepath"/>
              <method event="onconnect">
                        Debug.write("Connected with auth param: " + this.getAuthParam());
                </method>
                <method event="onerror" args="error">
                        Debug.write("Connection Error" + error);
                </method>
      </connection>
      <script>
              canvas.connection.setAuthParam('usr=guest');
              canvas.connection.connect();
      </script>
      <connectiondatasource name="agentDatasource">
    	  <dataset name="sampleQuote"/>
      </connectiondatasource>
    	

    You should see the connection message as displayed here:

  3. Send request to the QuoteServer with LPS acting as a http proxy When you click on the button to send the request, you should see the response from LPS. (I wonder if it is possible to get access to the response from the back-end server, will look into that later)
  4. Emulating the QuoteServer

    Now we have a persistant connection to LPS which acts as an agent between our client application and the back-end server, and we have faked an request to the faked back-end server.
    Next we'll emulate the QuoteServer pushing data to the application using the form below:

    Emulating the Server pushing data to the client:
    To:
    Dataset:
    Range:
    Group:
    Message:
    This is what you should get:

    Also note the response from LPS to the back-end server when you submit the form, this is helpful when you are actually implementing your server in a servlet.

  5. Getting the client connection status.

    When you are implementing your server, you might need to detect the client disconnecting without informing the server. You can use the agentlist to determine if a client is still connected.
    The following simulate the communication format for the agentlist protocol:

    Inquiring a user connection status:
    Group:
    Users:
    If the user is connected, you'll get a response like this:
    
    <lps>
        <status>200</status>
        <message>ok</message>
        <body>
            <list>
                <user name="guest"/>
            </list>
        </body>
    </lps>
    	
    You might want to try changing the user and submit again to see the response for a non-exsistent user.
Now you should have all you need to know in order to implement a real server. I've implemented one, but that is a bit too complicated as a tutorial example. I'll write another tutorial for that.
Stayed tune.

Send your comment/suggestion to: Jack Hung

Just thinking out loud:
  • Can the agent url be relative?
  • It would be nice if the agent url can be specify at deployment time, for example in a property resource.
  • As it is now, it is possible to bring up multiple client application instances using the same user name and the data are pushed to all of them. This could be a feature for some application but not for others.