Original article: http://bbs.mhhf.net/showtopic-336364.html
// ======================== App class ==========================
Application. onconnect /*
Application. ondisconnect /*
Application. onappstart // call the app Load
Application. onappstop // uninstall the application
Application. onstatus // An error occurred while calling the script
Application. broadcastmsg ("function", parameter )/*
Application. acceptconnection (newclient) // accept /*
Application. Disconnect (newclient) // disconnect /*
Application. getstats () // returns the network status of the application.
Application. registerclass // register or deregister a constructor
Application. registerproxy () // register an NC or client to complete a Method Request
Application. rejectconnection () // reject connection /*
Application. Shutdown () // uninstall the app
// ---- Attribute ----
Application. allowdebug // True False whether to allow the use of Manager
Application. Clients // connection Group
Application. config // allow access to xml configuration file attributes
Application. hostname // server host name
Application. Name // app Instance name /*
Applicatiseon. Server // platform and version
Application. GC // call the Garbage Collector to recycle unused resources of the app
Application. getstats // return the app status
Parameters:
Bytes_in // receive and send data
Bytes_out
Msg_in // number of messages accepted and sent
Msg_out
Msg_dropped // number of clients
Total_connects // total number of connections
Total_disconnects // total number of disconnections
// =============== App_client class =======
Client. getstats // return the client status
Client. readaccess // send a "ping" to the customer. If the response is received, true is returned.
Client. setbandwidthlimit () // sets the maximum bandwidth of the connection.
Client. Agent // customer version and Platform
Client. IP // the IP address of the client /*
Client. Protocol // client Protocol
Client. readaccess // list of client read access levels
Client. referrer // connected SWF or server URL
Client. Secure // Boolean value indicates whether the Internet connection is secure
Client. Uri // The URI determined by the client
Client. virtualkey // client type (Version)
Client. writeaccess // list of client write access
Call //
// =============== App_file class ============
Build Method
Fileobject = new file (name or URL)
File. Close // close this file
File. copyto // copy a file to another location
File. EOF // whether the file pointer is located at the end of the file
File. Flush // clear the buffer of the file output
File. List // if the file is a directory, an array is returned.
File. mkdir // create a directory
File. Open // open the file for reading or writing
File. Read // read a specified number of characters from the file and return a string
File. readbyte // read the next byte from the file and return the numeric value of the next byte
File. readln // read the next line from this file and return the string
File. Remove // remove the file or directory
File. renameto // move or rename the file
File. Write // write data to a file
File. writeall // unknown
File. writebyte // write a byte to this file
File. writeln // write data to the file and output the last parameter.
File. getglobal // skip a specified number of bytes and return a new file location
File. tostring returns the name of the file object.
//-Attributes
File. canappend // indicates that the file can be opened for append purposes.
File. Canread // whether it can be read
File. canreplace // whether to enable with replacement mark
File. creationtime // File Creation Time
File. exists // indicates whether the file or directory exists
File. isdirectory // whether it is a directory
File. isfile // whether it is a data file
File. isopen // whether the file is open
File. lastmodified // last modification time
File. Length // Directory: number of files. File: number of bytes in the file
File. Mode // file opening Mode
File. Name // file name
File. Position // current file offset
File. Type // encoding and data type used by the file
// ================================== Connect to the instance
// Client Connection
NC = new netconnection ();
// Process any status changes and responses from the server
NC. onstatus = function (Info ){
// The connection is successfully established.
If (info. Code = "netconnection. Connect. Success "){
Trace ("connection successful ");
} Else if (info. Code = "netconnection. Connect. Closed "){
Trace ("disconnect ");
} Else {
Trace ("unable to connect ")
}
};
NC. Connect ("rtmp: // 192.168.1.223/test ");
// Server connection
Application. onconnect = function (newclient ){
Application. acceptconnection (newclient );
};
Application. ondisconnect = function (newclient ){
};
// Response function of the server to the client
Client. Prototype. xxx = function (){
}
# Include "netdebug. As" // test the connection Effect
Connect. Connect ()
Application. onconnect = function (connection name, user name, user name ){}
Close. Close ()
Application. Disconnect (clientobj)
Application. ondisconnect = function (){}
Call
. Call ()
Call a server definition method. The method is defined with the main. ASC file.
Accept and get a response from the client
Application. acceptconnection (newclient)
Rejected and client response
Application. rejectconnection (newclient)
Server connection data
Entries_so = export dobject. Get ("room1/game_so", true );
// Set the global variables of the server
Gframeworkfc. getclientglobals (newclient). Username = username;
Connection example:
# Include "netdebug."
// Create a new connection object
Myconnection_nc = new netconnection ();
// Process any status changes and responses from the server
Myconnection_nc.onstatus = function (Info ){
Trace ("level:" + info. Level + "Code:" + info. Code );
};
// Start to connect to the server
Myconnection_nc.connect ("rtmp:/yc_sd/myinstance", "Kevin towes ");
// Establish the UI component to test whether the connection is successful
Peoplelist_mc.connect (myconnection_nc); // The Logon Name List component.
Connectionlight_mc.connect (myconnection_nc); // log on to the test component.
Data read/write example: (use the above connection to establish a connection first)
Initremotedomaindobject = function (){
Trace ("connect a remote login dobject ");
// Create a so database named myremoteso. The connection object is myconnection_nc.
Rem_so = export dobject. getremote ("myremoteso", myconnection_nc.uri, true );
// Set the data synchronization function
Rem_so.onsync = function (){
}
// Data connection
Rem_so.connect (myconnection_nc );
// Write data
Rem_so.data.simpletest = "flashcom will change my world ";
Rem_so.data.arraytest = ["Brett", "Mike", "Ryan", "Paul", "jody", "Kevin"];
// Read data
VaR my_var = rem_so.data.simpletest;
VaR my_array = rem_so.data.arraytest;
Trace ("remote export dobject read test:" + my_var );
Trace ("remote export dobject read test:" + my_array [0]);
Trace ("remote so size:" + rem_so.getsize ());
};
Data Interaction
Server:
// Header
Client. Prototype. getdata = function (){}
// Where
Client. getdata = function ()
{
VaR Ss = new array ("ASDF", 5666,6777)
Return SS
}
Client:
VaR s_result = new object ();
S_result.onresult = function (Info ){
// Info is the data returned by the server
Trace (Info );
};
Myconnection_nc.call ("getdata", s_result );
Server call customer
Newclient. Call ("test ");
As:
Myconnection_nc.test = function (){
Trace ("server call ");
};
Server Management mongodobject
// Connect to the shared
Application. game_so = export dobject. Get ("game_so", true );
// Write
Application. game_so.setproperty ("variable name", value)
// Read
Variable name = application. game_so.getproperty ("variable name ")
Trace (variable name)
// Read all variable names
Getpropertynames ()
Obtain the name of the returned user.
Application. onconnect = function (newclient, username, my_pic)
{
Application. acceptconnection (newclient );
// Add a name to the connection object
Newclient. Username = Username
}
Application. ondisconnect = function (newclient)
{
// Obtain the name of the returned user
Trace (newclient. username)
}
All connected participants
Application. Clients
Current entrant
This
Ui connection
Peoplelist_mc.connect (myconnection_nc );
AV video/audio
// Write
Myconnection_nc.connect ("rtmp:/av_test/myinstance", "test ");
Publish_ns = new netstream (myconnection_nc );
// Publish write parameter record: New append: append false: false, not recorded
Publish_ns.publish ("test", "false ");
Publish_ns.attachvideo (camera. Get ());
Publish_ns.attachaudio (microphone. Get ());
// Stop recording
Publish_ns.close ();
// Play
Play_ns = new netstream (myconnection_nc );
Play_video.attachvideo (play_ns );
Play_ns.play ("test ");
// Stop playing
Play_ns.close ();
// File Access
Fileobject = new file ("/AA/1.txt ")
// Fileobject. Open ("utf8", "read ")
If (fileobject. Open ("utf8", "read ")){
// Strval = fileobject. Read (1, 100 );
All = fileobject. readall ()
// T1 = fileobject. readln ()
// T2 = fileobject. readln ()
Fileobject. Close ()
Trace (all)
}
// Add Error Log Tracing
Application. onstatus = function (infoobject ){
VaR date_data = new date ();
VaR newdate = date_data.getfullyear () + "year" + (date_data.getmonth () + 1) + "month" + date_data.getdate () + "day ";
VaR newtime = date_data.gethours () + "hour" + date_data.getminutes () + "minute" + date_data.getseconds () + "Second ";
// Current date + time
VaR new_dd = newdate + "+ newtime;
VaR log_txt = ""
Log_txt + = "\ r \ n ---------"
Log_txt + = "\ r \ n log error time =" + new_dd + "error Instance name =" + application. Name
For (var I in infoobject ){
If (I = "level "){
Log_txt + = "\ r \ n error level =" + infoobject;
} Else if (I = "Code "){
Log_txt + = "\ r \ n code situation =" + infoobject;
} Else if (I = "Description "){
Log_txt + = "\ r \ n description =" + infoobject;
} Else if (I = "details "){
Log_txt + = "\ r \ n details =" + infoobject;
} Else if (I = "FILENAME "){
Log_txt + = "\ r \ n script file =" + infoobject;
} Else if (I = "lineno "){
Log_txt + = "\ r \ n error row COUNT =" + infoobject;
}
// Trace (I + ":" + infoobject );
}
Log_txt + = "\ r \ n ---------"
// Check whether the directory exists
Root_dir = new file ("/")
Dirobj = new file ("/error_logs /")
// Created when the directory does not exist
If (! Dirobj. exists ){
Trace ("created successfully ")
Root_dir.mkdir ("/error_logs ")
}
// Write data
VaR fileobj = new file ("/error_logs/invalid variable newdate1_1_.txt ")
// Fileobj. Open ("utf8", "read ")
If (fileobj. Open ("utf8", "APPEND ")){
// Strval = fileobj. Read (100 );
Fileobj. Write (log_txt );
Fileobj. Close ()
}
};