Packagecom.lightstreamer.as_client
Classpublic class LSClient
InheritanceLSClient Inheritance flash.events.EventDispatcher

LSClient is the engine that manages the communication with Lightstreamer Server. Because the browser's connection pool is usually tiny, it is recommended to use only one instance of LSClient per Flex application, to avoid pool saturation.



Public Methods
 MethodDefined By
  
Constructor for LSClient.
LSClient
  
Close the connection to the Server, if a connection exists. It is adviced to always call this method during the unload of the Flex application.
LSClient
  
getStatus():String
Inquiry method to know the current Client status.
LSClient
  
Open a stream connection to the Server with the supplied parameters and policies.
LSClient
  
Open a poll connection to the Server with the supplied parameters and policies.
LSClient
  
sendMessage(message:*):*
Send a message to Lightstreamer Server.
LSClient
  
setMaxBandwidth(bandwidth:*):void
Request a new maximum bandwidth for the next/current connection.
LSClient
  
subscribeTable(table:Table):void
Subscribe to a table on the Server.
LSClient
  
Unsubscribe from a table previously subscribed to.
LSClient
Events
 Event Summary Defined By
  Notification that a Connection is closed because of a Server decision.LSClient
  Notification of an error on the control connection.LSClient
  Notification of an error while receiving updates from the Server.LSClient
  Notification that the outcome of a sent message will not be received.LSClient
  Notification of a Server error in response to a sent message.LSClient
  Notification of the successful processing of a sent message.LSClient
  Notification of a Server error in response to a stream/poll request.LSClient
  Notification of connection status change.LSClient
Public Constants
 ConstantDefined By
  COMMAND : String = COMMAND
[static] String constant for the COMMAND subscription mode to be used with Table instances.
LSClient
  CONNECTING : String = CONNECTING
[static] String constant for the CONNECTING status of LSClient: The Client is trying to reach Lightstreamer Server.
LSClient
  DISCONNECTED : String = DISCONNECTED
[static] String constant for the DISCONNECTED status of LSClient: The Client is waiting for connection commands.
LSClient
  DISTINCT : String = DISTINCT
[static] String constant for the DISTINCT subscription mode to be used with Table instances.
LSClient
  MERGE : String = MERGE
[static] String constant for the MERGE subscription mode to be used with Table instances.
LSClient
  POLLING : String = POLLING
[static] String constant for the POLLING status of LSClient.
LSClient
  RAW : String = RAW
[static] String constant for the RAW subscription mode to be used with Table instances.
LSClient
  STALLED : String = STALLED
[static] String constant for the STALLED status of LSClient: The Client was receiving data from a Lightstreamer Server but the data flow now appears interrupted.
LSClient
  STREAMING : String = STREAMING
[static] String constant for the STREAMING status of LSClient.
LSClient
Constructor Detail
LSClient()Constructor
public function LSClient()

Constructor for LSClient. Empty constructor.

Method Detail
closeConnection()method
public function closeConnection():void

Close the connection to the Server, if a connection exists.

It is adviced to always call this method during the unload of the Flex application. Application code should capture the unload notification in whichever way the Flex environment provides, then call closeConnection.

For instance, the Javascript unload event on the container DOM element could be captured and closeConnection could be called via the Actionscript ExternalInterface class. Moreover on Internet Explorer it is sometimes necessary to give the application some extra time between the unload event and the closure of the application, to let the Flash Player close the socket. The Flex StockList Demo client example included in the SDK shows this technique.

The newer AjaxBridge component, if available, can be used in place of the ExternalInterface class to access the LSClient from Javascript code on the container DOM element.

See also

getStatus()method 
public function getStatus():String

Inquiry method to know the current Client status.

Returns
String — The current Client status.

See also

openConnection()method 
public function openConnection(info:ConnectionInfo, policy:ConnectionPolicy = null):void

Open a stream connection to the Server with the supplied parameters and policies. If a connection is already open, it is closed first.

The Stream-sense feature is enabled. If the network infrastructure blocks streaming mode, then the Client will switch to polling mode. If, however, an answer is finally received from the streaming connection after the polling connection has already been started, then the streaming connection can be recovered, depending on the setBufferedStreamingHandled setting on the "policy" argument.

In case of connection refusal by the Server, the issue is notified through a ServerErrorEvent.

Upon unload of the Flex application, an open connection should always be closed through closeConnection.

Edition Note: Connections from the Flex Client Library is an optional feature, available depending on Edition and License Type.

Parameters

info:ConnectionInfo — The connection parameters.
 
policy:ConnectionPolicy (default = null) — The connection policies. If not specified, default policies will apply.

See also

openPollingConnection()method 
public function openPollingConnection(info:ConnectionInfo, policy:ConnectionPolicy = null):void

Open a poll connection to the Server with the supplied parameters and policies. If a connection is already open, it is closed first. The Stream-sense feature is disabled (i.e. only poll connections will be used until a call to openConnection is issued).

In case of connection refusal by the Server, the issue is notified through a ServerErrorEvent.

Upon unload of the Flex application, an open connection should always be closed through closeConnection.

Edition Note: Connections from the Flex Client Library is an optional feature, available depending on Edition and License Type.

Parameters

info:ConnectionInfo — The connection parameters.
 
policy:ConnectionPolicy (default = null) — The connection policies. If not specified default policies will apply.

See also

sendMessage()method 
public function sendMessage(message:*):*

Send a message to Lightstreamer Server. The message is associated to the current session and is interpreted and managed by the Metadata Adapter related to that session.

Upon subsequent calls to the method, the sequential management of the messages is guaranteed. However, any message that, for any reason, doesn't reach the Server can be discarded by the Server if this causes the subsequent message to be kept waiting for longer than a configurable timeout. A shorter timeout can be associated with the subsequent message itself. A sequence identifier can also be associated with the messages. In this case, the sequential management is restricted to all subsets of messages with the same sequence identifier associated. In case the sequential management is undesired, the special UNORDERED_MESSAGES sequence identifier can be used.

Note that messages are sent to the Server asynchronously with respect to the Client thread and that the real outcome of the request should be obtained by listening for SendMessagevent events. Unless the return value is false, one of those events will be eventually sent. Events associated with the same sequence are guaranteed to be issued in sequence.

Parameters

message:* — A Message instance or a text String to be interpreted by the Metadata Adapter. It should not be null.

If a text String is supplied, a sequence identifier made by an empty string will be considered, hence all messages sent with this syntax belong to the same sequence.

Returns
* — false if no session is open; in the other case, if a String was given, true is returned (this is for backward compatibility); otherwise, if a Message instance was given, a number representing the progressive number of the message within its sequence is returned (starting from 1). Note that each time a new session is established the progressive number is reset.

Note that if no session is open, no attempt of sending the message will be performed; however, as messages are sent to the Server asynchronously, if a session is open but ends before the message is sent, then no attempt of sending the message will be performed either, but a SendMessageAbortEvent event will be sent.


Throws
ConfigurationError — An invalid object was specified as message.

See also

setMaxBandwidth()method 
public function setMaxBandwidth(bandwidth:*):void

Request a new maximum bandwidth for the next/current connection. The new limit overrides any previous limit. The limit can only be used in order to restrict the constraints set by Lightstreamer Server Metadata Adapter.

Parameters

bandwidth:* — The maximum bandwidth requested for the stream or poll connection, expressed in kbps (kilobits/sec). The string "unlimited" is also allowed, to mean that the maximum bandwidth can be decided on the Server side. Default value is "unlimited".


Throws
ConfigurationError — An invalid value was specified.
subscribeTable()method 
public function subscribeTable(table:Table):void

Subscribe to a table on the Server.

Parameters

table:Table — The table object to be subscribed to.


Throws
SubscriptionError — The table is already subscribed.

See also

unsubscribeTable()method 
public function unsubscribeTable(table:Table):void

Unsubscribe from a table previously subscribed to.

Parameters

table:Table — The table to be unsubscribed from.


Throws
SubscriptionError — The table is not subscribed.
Event Detail
ConnectionDropEvent Event
Event Object Type: com.lightstreamer.as_client.events.ConnectionDropEvent
ConnectionDropEvent.type property = com.lightstreamer.as_client.events.ConnectionDropEvent.CONNECTION_DROP

Notification that a Connection is closed because of a Server decision.

Define the value of the type property of a ConnectionDrop event object.
ControlConnectionErrorEvent Event  
Event Object Type: com.lightstreamer.as_client.events.ControlConnectionErrorEvent
ControlConnectionErrorEvent.type property = com.lightstreamer.as_client.events.ControlConnectionErrorEvent.CONTROL_CONNECTION_ERROR

Notification of an error on the control connection.

Define the value of the type property of a ControlConnectionError event object.
DataErrorEvent Event  
Event Object Type: com.lightstreamer.as_client.events.DataErrorEvent
DataErrorEvent.type property = com.lightstreamer.as_client.events.DataErrorEvent.DATA_ERROR

Notification of an error while receiving updates from the Server.

Define the value of the type property of a DataErrorEvent event object.
SendMessageAbortEvent Event  
Event Object Type: com.lightstreamer.as_client.events.SendMessageAbortEvent
SendMessageAbortEvent.type property = com.lightstreamer.as_client.events.SendMessageAbortEvent.SEND_MESSAGE_ABORT

Notification that the outcome of a sent message will not be received.

Define the value of the type property of a SendMessageAbort event object.
SendMessageErrorEvent Event  
Event Object Type: com.lightstreamer.as_client.events.SendMessageErrorEvent
SendMessageErrorEvent.type property = com.lightstreamer.as_client.events.SendMessageErrorEvent.SEND_MESSAGE_ERROR

Notification of a Server error in response to a sent message.

Define the value of the type property of a SendMessageError event object.
SendMessageProcessedEvent Event  
Event Object Type: com.lightstreamer.as_client.events.SendMessageProcessedEvent
SendMessageProcessedEvent.type property = com.lightstreamer.as_client.events.SendMessageProcessedEvent.SEND_MESSAGE_PROCESSED

Notification of the successful processing of a sent message.

Define the value of the type property of a SendMessageProcessed event object.
ServerErrorEvent Event  
Event Object Type: com.lightstreamer.as_client.events.ServerErrorEvent
ServerErrorEvent.type property = com.lightstreamer.as_client.events.ServerErrorEvent.SERVER_ERROR

Notification of a Server error in response to a stream/poll request.

Define the value of the type property of a ControlError event object.
StatusChangeEvent Event  
Event Object Type: com.lightstreamer.as_client.events.StatusChangeEvent
StatusChangeEvent.type property = com.lightstreamer.as_client.events.StatusChangeEvent.STATUS_CHANGE

Notification of connection status change.

Define the value of the type property of a StatusChange event object.
Constant Detail
COMMANDConstant
public static const COMMAND:String = COMMAND

String constant for the COMMAND subscription mode to be used with Table instances.

CONNECTINGConstant 
public static const CONNECTING:String = CONNECTING

String constant for the CONNECTING status of LSClient: The Client is trying to reach Lightstreamer Server.

DISCONNECTEDConstant 
public static const DISCONNECTED:String = DISCONNECTED

String constant for the DISCONNECTED status of LSClient: The Client is waiting for connection commands.

DISTINCTConstant 
public static const DISTINCT:String = DISTINCT

String constant for the DISTINCT subscription mode to be used with Table instances.

MERGEConstant 
public static const MERGE:String = MERGE

String constant for the MERGE subscription mode to be used with Table instances.

POLLINGConstant 
public static const POLLING:String = POLLING

String constant for the POLLING status of LSClient. The Client is receiving real-time updates from Lightstreamer Server in polling mode.

RAWConstant 
public static const RAW:String = RAW

String constant for the RAW subscription mode to be used with Table instances.

STALLEDConstant 
public static const STALLED:String = STALLED

String constant for the STALLED status of LSClient: The Client was receiving data from a Lightstreamer Server but the data flow now appears interrupted.

STREAMINGConstant 
public static const STREAMING:String = STREAMING

String constant for the STREAMING status of LSClient. The Client is receiving real-time updates from Lightstreamer Server in streaming mode.