Sharedobject use: Use shared objects in Fluorinefx.net and flex to maintain online user list instances "Go"

Source: Internet
Author: User

First, add a new FluorineFX service class project Onlineservice, delete the original Sample.cs, and add a user class definition with a Applicationadpater class:

/*--User.cs--*/

Namespace Onlineservice

{

public class User

{

public string UserName {get; set;}

public string USERPSW {get; set;}

}

}

/*--Applicationadapter class: DemoApp.cs--*/

Using FluorineFX;

Using FluorineFx.Messaging.Adapter;

Using FluorineFx.Messaging.Api;

Using FluorineFx.Messaging.Api.SO;

Namespace Onlineservice

{

<summary>

Fluorine sample service.

</summary>

[Remotingservice ("User Login Status Test program")]

public class Demoapp:applicationadapter

{

public override bool AppConnect (iconnection connection, object[] parameters)

{

String userName = Parameters[0] As String;

string password = parameters[1] As String;

Here you can customize the login judgment verification logic, here as long as the password is 000 to enter

if (Password! = "000")

return false;

Adds a username attribute to the current connection to the current logged-on user.

So that when this connection is dropped, it can be accurately positioned to its relevant user

Connection. Client.setattribute ("UserName", userName);

Get Shared Object (Onlineusers)

Isharedobject Users_so = Getsharedobject (connection. Scope, "onlineusers");

if (Users_so = = null)

{

The first user when the shared object does not exist, you need to create a

Createsharedobject (connection. Scope, "Onlineusers", false);

Users_so = Getsharedobject (connection. Scope, "onlineusers");

}

Update Shared object key is user name, value is User object

Value can be a more complex object, but try not to package a list or array, because flex-side unpacking is not easy

Users_so. SetAttribute (UserName, New User () {userName = userName, USERPSW = password});

return true;

}

public override void Appdisconnect (Iconnection connection)

{

String userName = connection. Client.getattribute ("UserName") as String;

Isharedobject Users_so = Getsharedobject (connection. Scope, "onlineusers");

if (users_so! = null)

{

Remove the currently exiting system user from the shared object

Users_so. RemoveAttribute (UserName);

}

Base. Appdisconnect (connection);

}

}

}

Second, add a fluorine.net Web project to the solution

2.1 Add the Apps folder under the Web root, add the Onlineuser folder under Apps, add the App. config profile under the Onlineuser folder, and under Configure the application to process the DemoApp defined above as follows:

2.2 Modify Service-config.xml under Web-inf to open its MY-RTMP Channel configuration section (FluorineFX added Web project, this section is commented out by default, open)

2.3 Under the root directory to add the flex file, under which added Libs, SRC, swf three subfolders, FDS.SWC into the Libs folder, the other two folders in the following steps, respectively, as the source files and output files directory of the Flex project.

The documentation for the project is organized as follows:

Third, in Flex Builder3 new Project Onlineuserdemo, the project path is 2.3 in the Flex folder, configure the test server for the Asp.net,webrooturl path to vs run the site when the path, such as the blue part:

3.1 Right-click the properties of the Flex project,

The configuration Flexbuilderpath is as follows:

The parameters for configuring Flexcompier are as follows:

Note: The above "E:.." Please replace the path in your local project Services-config.xml (including the server configuration below)

The parameters for configuring Flexservce are as follows:

3.2 Below is Onlineuserdemo.mxml source code:

<?xml version= "1.0" encoding= "Utf-8"?>

<mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" layout= "Absolute"

Width= "height=" 382 "backgroundgradientalphas=" [1.0, 1.0] "

Backgroundgradientcolors= "[#000000, #049FF1]" fontsize= ">

<mx:Script>

<! [cdata[

Import Mx.controls.Alert;

Import Mx.messaging.config.ServerConfig;

private Var nc:netconnection;

private Var So:sharedobject;

Private Function Connectionserver (event:mouseevent): void

{

var endpoint:string=serverconfig.getchannel ("My-rtmp"). Endpoint;

NC = new Netconnection ();

Nc.connect (endpoint+ "/onlineuser", This.txtusername.text,this.txtpassword.text);

Nc.addeventlistener (Netstatusevent.net_status,onstatushandler);

Nc.client = this;

}

Private Function Onstatushandler (event:netstatusevent): void

{

This.connStatus.text = "Connection Status:" + Event.info.code;

if (Event.info.code = = "NetConnection.Connect.Success")

{

Connecting remote shared objects

so = Sharedobject.getremote ("Onlineusers", Nc.uri,false);

if (SO)

{

So.addeventlistener (Syncevent.sync,onsynchandler);

So.connect (NC);

So.client = this;

}

Oncallclient ("User" <font color=\ "#FF0000 \" > "+this.txtusername.text+" </font> "landed the system! ");

}

}

Private Function Onsynchandler (event:syncevent): void

{

var temp:array = new Array ();

Each element in the So.data is a server-side maintenance attribute

for (Var u:object in So.data)

{

Temp.push (So.data[u]);

}

This.dgUserList.dataProvider = temp;

}

Private Function Oncallclient (message:string): void

{

So.send ("writemsg", message);

So through the Send method, you can call each client's WRITEMSG program at the same time, like sending a broadcast

}

Writemsg must be public, otherwise so does not call

Public Function Writemsg (message:object): void

{

var param:string=message.tostring ();

Txttracearea.htmltext + = param + "\ n";

Txttracearea.validatenow ();

Txttracearea.verticalscrollposition = txttracearea.maxverticalscrollposition;

}

]]>

</mx:Script>

<mx:label x= "302" y= "153" id= "Connstatus" width= "288" color= "#FFFFFF"/>

<mx:label x= "302" y= "181" id= "Nowroom" width= "288" color= "#FFFFFF"/>

<mx:datagrid x= "y=" "height=" 332 "width=" 248 "id=" Dguserlist ">

<mx:columns>

<mx:datagridcolumn datafield= "UserName" headertext= "name"/>

<mx:datagridcolumn datafield= "USERPSW" headertext= "Honey Code"/>

</mx:columns>

</mx:DataGrid>

<mx:form x= "302" y= "width=" >

<mx:formitem label= "user name:" color= "#FFFFFF" >

<mx:textinput id= "txtUserName" width= "" "color=" #000000 "/>

</mx:FormItem>

<mx:formitem label= "Password:" color= "#FFFFFF" >

<mx:textinput id= "Txtpassword" width= "130"

Color= "#000000" displayaspassword= "true"/>

</mx:FormItem>

<mx:formitem label= "" >

<mx:button label= "Login Server" click= "Connectionserver (event)"

Enabled= "{this.txtusername.text.length&gt;0?true:false}" color= "#FFFFFF"/>

</mx:FormItem>

</mx:Form>

<mx:textarea x= "302" y= "209" width= "288" height= "153" alpha= "1.0"

Backgroundcolor= "#F2D2D2" backgroundalpha= "0.26" color= "#FFFFFF"

Id= "Txttracearea" bordercolor= "#FFFFFF"/>

</mx:Application>

Category: Flourinefx.net usage Tags: fluorinefx, Flex, ActionScript, Sharedobject green channel: Good text to the top attention to my collection this article contact me the most handsome sheep in the pen
Follow-1
Fans-0 + plus attention00(Please comment on the article) «Previous: Flex and AS3 Learning notes: Part 3 function parameters, string processing, date and time types
» Next: The relationship between Netconnection and NetStream in Flex, and the number of browser concurrent connections test posted @2012-02-08 13:45 The most handsome sheep in the pen. Read (194) Comments (1) Edit Collection


Post a commentReply Reference#1楼 [Landlord] 2012-02-08 13:46 | The most handsome sheep in the fold This example source code download:
Click to download

Sharedobject use: Use shared objects in Fluorinefx.net and flex to maintain online user list instances "Go"

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.