QxTransformer Wiki

Message Transport

The information on this page does not correspond to the current release (0.3alpha1). We offer no support on this yet.

As already mentioned, messages can not only be passed between objects within the client, they can also be exchanged between objects living on server and client, or even on different clients connected to the server. If, for example, you want to forward client messages that start with “servermessages” to the server, you can set up a message transport easily:

<qx:messageTransport 
filter="servermessages.*"
mode="toServer"
serviceUrl="../backend/php/services/index.php"
serviceName="myservice.myserviceclass"
serviceMethod="handleClientMessages">

</qx:messageTransport>

This code assumes that you have an JSON-RPC backend which implements a myservice.myserviceclass with a “handleClientMessages” method. This method, for example, could perform specific actions based on the message or even forward them to other clients.

The reverse way - forwarding messages from the server to the client - is less easy to implement since http is a protocol initiated by the client and not the server, and “push” technologies (such as cometd) are still in their infancy.

The QxTransformer databinding mechanisms fetches and dispatches server messages with every rpc call. That is, if the returned data is an object and this object contains a “__messages” property, the value of this property is treated as a hash map of message names and message data.

This, however, is unrealiable since the server messages are fetched only if the client makes a request. For example, in a chat application, the client window displaying the conversation needs to display new text entered by the remote user whenever he or she has typed it, and not only after the local user types something. One way to get messages that might be waiting is to periodically poll the server. With the QxTransformer message transport, we do this like so:

<qx:messageTransport 
filter="*"
mode="toClient"
interval="2000"
serviceUrl="../backend/php/services/index.php"
serviceName="myservice.myserviceclass"
serviceMethod="getServerMessages">

</qx:messageTransport>

This will poll the server every 2 seconds and dispatch the received messages.

  Sign in   Home   Sitemap   Terms   Report Abuse   Print  |  Powered by Google Sites