BeamServer Flash Component
Introduction
The client side BeamServer component for Flash contains two classes: BSEvent and BSClent, this both are located in BeamServerClient.swc library, which is contained in BeamServer basic package. BeamServerClient.swc must be installed inside Flash and imported into the library in order to this classes are visible inside our application.
BSEvent class extends flash.events.Event and contains a parameter named "Result", where all data associated with the BeamServer events are located.
The following Actionscript code shows the use of the BSEvent class:
var client: BSClient = new BSClient();
function NodeAddedHandler(event: BSEvent)
{
var name: String = event.Result.name;
var nodeId: int = event.Result.nodeId;
...
}
client.addEventListener(“OnNodeAdded”, NodeAddedHandler);
This class is the core of any Flash application using BeamServer. It contains all the necessary functionality for connect with BeamServer, move through nodes, create and destroy nodes, do subscriptions, modify attributes and access to all functionalities of BeamServer. BSClient class also generates all events associated with the server.
The following methods are available in BSClient class:
ConnectToServer(ip:String, port:uint, pfile:String, pport:int) Connects to the BeamServer server associated to the IP address and the specified port. If successful an OnConnect event is dispatched, otherwise an OnError event is dispatched. ip: String - Server IP address. |
CloseConnection() Closes the connection with the server. When the connection is closed an OnDisconnect event is dispatched. |
GetId():int Output: Returns the unique ID of the node that represents our connection inside the server. |
LoginToServer(user:String,pass:String) Sends a login request to the server with the user name and password specified. It is esential to do this before any other operation on the server. Once the request has been procesed by the server an OnLogin event is received, indicating the success or failure of the proccess. user: String – User name. |
JoinNode(nodeId:uint,user:String,pass:String) This function makes our connection node join to the node list of the specified node. nodeId: uint –Unique ID of the node we want to join. |
SubscribeToNode(nodeId:uint) This does a subscription to the node with the specified ID. After this we will receive events associated to any change performed in the node. nodeId: uint – Unique ID of the node we want to subscribe to. |
UnsubscribeFromNode(nodeId:uint) Cancels the subscription with the node with the specified ID. nodeId: uint – Unique ID of the node we want to unsubscribe from. |
SendObject(nodeId:uint,data:Object) Sends data to the node with the specified ID. Any data type can be sent but there are some compatibility issues to take into account (See the end of this document). nodeId: uint –Unique ID of the node we want to send data to. |
LeaveNode(nodeId:uint) Removes our node from the node list of the specified node. nodeId: uint – Unique ID of the node we want to exit from. |
CreateNode(nodeId:uint,name:String,param:Object) Creates a new node with the name and attributes specified, and adds it to the node list of the node with the specified ID. nodeId: uint – Unique ID of the parent node. |
DestroyNode(nodeId:uint) Destroys the node with the specified ID. nodeId:uint – The node ID of the node we want to destroy. |
SetAttribute(nodeId:uint,name:String,value:Object) Changes the value of the attribute with the specified name in the node with the specified ID. If the attribute doesn't exists, a new attribute is created, if the value is null, the attribute is destroyed. nodeId: uint – Unique ID of the node. |
SetChildAttribute(nodeId:uint,childId:uint,name:String,value:Object) Changes the value of the attribute with the specified name in the node with the specified ID (childId), inside the node list of the node with the specified ID (nodeId). If the attribute doesn't exists, a new attribute is created, if the value is null, the attribute is destroyed. nodeId: uint – Unique ID of the parent node. |
FindNodeByName(name:String) Sends a search request to look for a node by its name. The search context is global, searching in all the server structure. This method will generate an OnNodeFound event. name: String - Node name. |
Events generated by BSClient and content of the parameter "Result"
| OnConnect | |
| OnDisconnect | |
| OnError | |
| OnLogin | sender:uint - Event origin node. nodeId:uint - My own ID, if success. |
| OnJoinNode | sender:uint - Event origin node. |
| OnNodeAdded | sender:uint - Event origin node. |
| OnNodeRemoved | sender:uint - Event origin node. nodeId:uint - Removed node ID. |
| OnChildAttributeUpdated | sender:uint - Event origin node. |
| OnAttributeUpdated | sender:uint - Event origin node. |
| OnObjectReceived | sender:uint - Event origin node. |
| OnLeaveNode | sender:uint - Event origin node. |
| OnNodeDestroyed | sender:uint - Event origin node. nodeId:uint - Destroyed node ID. |
| OnNodeFound | sender:uint - Event origin node. found:boolean - True or False. nodeId:uint - Node ID if found, 0 otherwise. |
The Flash installation folders may change with different product versions, OS languages and user preferences.
Once we have put the component in the correct folder and we have checked it is on the component Flash window we can use it.
Drag the BeamServer client component from the components window to the library window and add the following code lines in your code:
import BeamServer.BSClient;
import BeamServer.BSEvent;
we can access this two classes now.
Client-Server data transference
Communication between the Flash client application and BeamServer is done using the "SendObject" and "OnObjectReceived" methods.
Virtually any data type can be transferred, however we should take into account some platform compatibility issues.
.NET type Flash type