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.
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:String):Boolean
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
  
unsubscribeTable(table:Table):void
Unsubscribe from a table previously subscribed to.
LSClient
Events
 EventSummaryDefined by
   Notification of an error on the control connection.LSClient
   Notification of a Server error in response to a control request.LSClient
   Notification of a Server error in response to a stream/poll request.LSClient
   Notification of connection status change.LSClient
Public Constants
 ConstantDefined by
  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
  POLLING : String = "POLLING"
[static] String constant for the "POLLING" status of LSClient.
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.
Upon unload of the Flex application, an open connection should always be closed through closeConnection.
Edition Note: Connections from the Flex Client Library are not supported by the Server, if it runs in Allegro edition.

Edition Note: Connections from the Flex Client Library are not supported by the Server, if it runs in Moderato edition.

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).
Upon unload of the Flex application, an open connection should always be closed through closeConnection.
Edition Note: Connections from the Flex Client Library are not supported by the Server, if it runs in Allegro edition.

Edition Note: Connections from the Flex Client Library are not supported by the Server, if it runs in Moderato edition.

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:String):Boolean

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.

Parameters
message:String — Any text string, to be interpreted by the Metadata Adapter. It should not be null.

Returns
Boolean — true if a session is open; false in the other case. Note that messages to the Server are sent asynchronously with respect to the Client thread. If the server session ends before the message is sent, then that message will never reach the Server.
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
ControlConnectionErrorEventevent 
Event object type: com.lightstreamer.as_client.events.ControlConnectionErrorEvent

Notification of an error on the control connection.

ControlErrorEventevent  
Event object type: com.lightstreamer.as_client.events.ControlErrorEvent

Notification of a Server error in response to a control request.

ServerErrorEventevent  
Event object type: com.lightstreamer.as_client.events.ServerErrorEvent

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

StatusChangeEventevent  
Event object type: com.lightstreamer.as_client.events.StatusChangeEvent

Notification of connection status change.

Constant detail
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.

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.

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.