Flash FMS helloword

Source: Internet
Author: User

There are some demos after the system is installed.

Installation path \ Adobe \ Flash Media Server 3.5 \ documentation \ Samples

There are many examples

 

Applications folder

You can create a folder, for example, firstapp, and an application. All the FLV files on the project server will be shared here, sometimes, when the server needs to write a program, there will be a main. ASC file. This is the server-side program. Currently, the server-side program only supports AS1 writing and is executed on the server. You can also use trace debugging. You can see how to trace the management server, you may create several apps and run them simultaneously on a server, such as video apps and chat room apps... All these apps are managed through fms2_console.swf of the FMS. Now let's take a look at how to manage the server!

Manage servers ~
Click Tools/fms_adminconsole.swf. Although it is just a SWF, it depends on him in the background management. enter your password and user during installation, and write localhost to the server address, get familiar with him


This view application is the most commonly used method for writing programs. When a client connects to the server, the app connected to the server is listed on the left, number of connections to the BS folder under the Applications folder (BS folder, because each folder corresponds to an app, that is, bs app ), the number of connections is 1,458, which is the Instance name (the default Instance name is _ definst _. Each folder can have several instances, which do not affect each other. This feature can be used for chatting in a room and will be used later)


After an app is selected or the client is connected, the status of the currently opened app is displayed.


Here is the trace on the live log server. The right side is the client, shared object, stream, and execution (memory usage, CPU usage, etc.). There are two small buttons behind it, usually used for debugging. Reload and unload!
Every time the main. ASC on the server is modified, remember to reload or unload it. Otherwise it will not take effect. Unload will close the window and automatically open the window when a client is connected.
Someone always tells me that his FMS is often abnormal. For example, if the connection fails, the code will be deleted and executed, and the folders will be deleted in a lifetime, I suspect there is a problem with my Rp ..
This is not an RP problem. Remember to reload the error! Click stopserverservice. bat in the Tools Folder.

Conf folder

Another important thing is the conf folder, which contains some server-side configuration files that may be used later. Do not change them first ....

Since then, the installation has ended, go on...

There is a protocol called rtmp

 

Rtmp protocol Overview
Introduction:

The rtmp protocol is used by flash for object, video, and audio transmission. The Protocol is established over TCP or HTTP.
The rtmp protocol is like a container for loading data packets. The data can be AMF data or FLV video/audio data.
A single connection can transmit multiple network streams through different channels. packages in these channels are transmitted according to fixed packages.

Connection)

Simple code for connecting to and playing a stream with an ActionScript:
Copy content to clipboard
Code:
VaR videoinstance: Video = your_video_instance;
VaR NC: netconnection = new netconnection ();
VaR connected: Boolean = nC. Connect ("rtmp:/localhost/MyApp ");
VaR ns: netstream = new netstream (NC );
Videoinstance. attachvideo (NS );
NS. Play ("flvname ");
The default port is 1935.

Handshake

Client → server: Send a handshake request to the server. this is not part of the protocol package. The first byte of the handshake request is (0 × 03), followed by 1536 bytes. it seems that this part of content is not crucial for the rtmp protocol, but it cannot be taken at will.
Server → client: the server responds to the handshake request from the client. this part of the data is still not part of the rtmp protocol. in fact, the response bytes are still (0x03), but the back is followed by a mass with a length of 1536 bytes (a total of 3072. the first 1536 pieces seem to be any content, or even null. the second code block of 1536 is the content of the handshake request sent from the client to the server in the previous step.
Client → server: The second 1536-byte data block that the server responded to the client from the previous step.

Now the handshake between the client and the server ends, and the rtmp Package content will be sent below.

Client → server: Send a connection package to the server.
Server → client: Server Response.

... And so on ......

Next, let's look at the example above.

Open the helloworld folder

 

Helloworld. ASC

The ASC file is used to store the ActionScript files that will be executed on the computer running Flash Media Server.

These files provide server-side logic functions that can be used together with the ActionScript In the SWF file.

Put helloworld. ASC in the new helloworld folder in the Applications folder.

Helloworld. ASC File Content

 

Code /*
* (C) Copyright 2007 Adobe Systems inconfigurated. All rights reserved.
*
* Notice: Adobe permits you to use, modify, and distribute this file in accordance with
* Terms of the Adobe License Agreement accompanying it. If you have already ed this file from
* Source other than Adobe, then your use, modification, or distribution of it requires the prior
* Written permission of adobe.
* This code and information is provided "as-is" without warranty
* Any kind, either expressed or implied, including but not limited
* The implied warranties of merchantability and/or fitness for
* Particle purpose.
*
* This code is not supported by Adobe Systems inreceivated.
*
*/

// Server-side action taken upon CONNECT request.
Application. onconnect = function (client ){

// Define new client function for a NC. Call ().
Client. serverhellomsg = function (hellostr ){
Return "hello," + hellostr + "! ";
}

// Accept the connection.
Application. acceptconnection (client );
}

 Summary of application-class event Processors
Application. onappstart is called when the application is loaded by the server.

Application. onappstop is called when the application is uninstalled by the server.

Application. onconnect is called when a client connects to the application.

Application. onappstop is called when the application is uninstalled by the server.

Application. onconnect is called when a client connects to the application.

Application. onconnectaccept is called when a client successfully connects to the application. It is only used for communication components.

Application. onconnectreject is called when a client fails to connect to the application. It is only used for communication components.

Application. ondisconnect is called when a client disconnects from the application.

Application. onstatus is called when a script produces an error.

 

We use CS3 to create a helloworld. fla test run OK.

 

Finally, let's take a look at helloworld. fla's corresponding corner file helloworld..

Code /*
* (C) Copyright 2007 Adobe Systems inconfigurated. All rights reserved.
*
* Notice: Adobe permits you to use, modify, and distribute this file in accordance with
* Terms of the Adobe License Agreement accompanying it. If you have already ed this file from
* Source other than Adobe, then your use, modification, or distribution of it requires the prior
* Written permission of adobe.
* This code and information is provided "as-is" without warranty
* Any kind, either expressed or implied, including but not limited
* The implied warranties of merchantability and/or fitness for
* Particle purpose.
*
* This code is not supported by Adobe Systems inreceivated.
*
*/

Package {

Import flash. display. movieclip;
Import flash.net. responder;
Import flash.net. netconnection;
Import flash. Events. netstatusevent;
Import flash. Events. mouseevent;


Public class helloworld extends movieclip {

// Represents a network connection.
Private var NC: netconnection;

// Responder for call to server's serverhellomsg -- see onreply () below.
Private var myresponder: responder = new Responder (onreply );


// Constructor.
Public Function helloworld (){
// Set display values.
Textlbl. Text = "";
Connectbtn. Label = "Connect ";

// Register a listener for mouse clicks on the button.
Connectbtn. addeventlistener (mouseevent. Click, connecthandler );
}


// When button is pressed, connect to or disconnect from the server.
Public Function connecthandler (Event: mouseevent): void {
If (connectbtn. Label = "Connect "){
Trace ("connecting ");

NC = new netconnection ();

// Connect to the server.
NC. Connect ("rtmp: // localhost/helloworld ");

// Call the server's client function serverhellomsg, in helloworld. ASC.
NC. Call ("serverhellomsg", myresponder, "world ");

Connectbtn. Label = "Disconnect ";

} Else {
Trace ("disconnecting ");

// Close the connection.
NC. Close ();

Connectbtn. Label = "Connect ";
Textlbl. Text = "";
}
}

// Responder function for NC. Call () in connecthandler ().
Private function onreply (Result: Object): void {
Trace ("onreply replicated ed value:" + result );
Textlbl. Text = string (result );
}

}
}

 

 

 

 

 

 

 

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.