Flex and. NET Interop (12)

Source: Internet
Author: User
Tags bool

Flex vs. NET Interop (12): Fluorinefx.net in-time communication applications (Remote Shared Objects) (iii)

Remote shared objects (a remote shared Objects) can be used to track, store, share, and multitask data synchronization operations for long clients. As long as the data on the shared object has changed, the latest data will be synchronized to all application clients that are connected to the shared object. FLUORINEFX provides remote shared objects (remotely shared Objects) and FMs shared objects, and for friends who are familiar with FMS development, Learning FluorineFX remote shared objects is very simple.

Shared objects can be created on the server side or on the client. The method of creating shared objects on the client is the same as using FMS development, creating a Netconnection object, connecting to the server through the Connect () method of the object, and then passing through Sharedobject.getremote () method, you can create a remote shared object on the client. The following instance code:

private function  connectionServer():void
{
    var nc:NetConnection = new NetConnection();
 nc.connect ("rtmp://localhost:1617/SOAPP","username","password")
    nc.addEventListener (NetStatusEvent.NET_STATUS,onStatusHandler);
 nc.client = this;
 }

private function  onStatusHandler(event:NetStatusEvent):void
{
    if(event.info.code ==  "NetConnectin.Connect.Success")
    {
        createSharedObject();
 }
}

private function createSharedObject():void
{
    var so:SharedObject = SharedObject.getRemote ("OnLineUsers",nc.uri,false);
 so.addEventListener(SyncEvent.SYNC,onSyncHandler);
 so.connect (this.nc);
 so.client = this;
 }

private function onSyncHandler(event:SyncEvent):void
{
   //.....do other
}

There is a big difference between creating remote shared objects and FMS on the server side of FluorineFX, and the FluorineFX Isharedobjectservice interface provides a method specifically for creating remote shared Objects Createsharedobject (), Applicationadapter implements this interface method. The definition is as follows:

public bool  CreateSharedObject(IScope scope, string name, bool persistent)
{
      ISharedObjectService service =  (ISharedObjectService)ScopeUtils.GetScopeService(scope, typeof(ISharedObjectService));
 return  service.CreateSharedObject(scope, name, persistent);
 }

If you want to create a remote shared object on the server side, you can call the Createsharedobject () method in the Applicationadapter class directly. The following is a code block for creating a remote shared object on the FluorineFX server side:

ISharedObject users_so = GetSharedObject(connection.Scope, "OnLineUsers");
if (users_so ==  null)
{
       //创建共享对象
        CreateSharedObject(connection.Scope,  "OnLineUsers", false);
 users_so = GetSharedObject(connection.Scope, "OnLineUsers");
 }

To update the data client in a shared object or to use the SetProperty () method, the FluorineFX server updates the shared object in a way that is not the same as FMS, The setattribute () and RemoveAttribute () methods provided by the FluorineFx.Messaging.Api.IAttributeStore interface are used to update the data in the shared object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.