Flash media startup Flash Media Server started

Source: Internet
Author: User
Tags connect client advantage
Server

Recently to a new company, finally out of the art of the bundle Rao, now a study of the code is good.
The project needs, must learn ~ in the way of learning to record, there are wrong place hope Master to give advice.
What is Flash Media Server?
Flash family member, formerly known as Flash Communication Server, the legendary FCS is this? Now it's time to call it a FMS ...
Do not know oh, see really terrible, mm and so cool Dongdong, since met her, let me do little things of interest all gone, I want to study this
What does this stuff do?
Flash chat room Ah, online video conferencing ah ah, network games?
Anyway, try it first.
Download the free developer version here first.
http://www.macromedia.com/software/flashmediaserver/
Then install, install remember username and password do not blindly fill yourself to remember, otherwise it seems to be reloading again.
I loaded the C disk, found the directory
C:\Program Files\macromedia\flash Media Server 2


You need to open the server first!
Start = = = Program ===macromedia===flash Media Server 2
There are two start****, all to open, shut down two, if you are afraid of trouble directly to find Tool folder in the batch file Startserverservice.bat it, he will help you fix the ground, want to close to find Stopserverservice.bat. ~
Manage Servers ~
Opened to be managed Oh, point open fms2_console.swf, don't look at him just a SWF, backstage management depend on him, enter your installation time password and user, server address write localhost good
See, familiar with him.
Applications folder
You can build a folder in it, such as Firstapp, all future FLV files on the server side of the project, and share files.
Conf folder
Also important is the Conf folder, which is some server-side configuration files, may be used in the future, do not move first ....
Come here today ... Waiting for the ~8

There's a protocol called RTMP.
Client and server-side communication is rtmp using protocol
Now build a Test1 folder in the server-side Applications folder (of course my client and server side is a machine) and your address is

Rtmp:/test1 or Rtmp://localhost/test1.

Note the "/" symbol in the two addresses
Turn on Flash
Communication with the server first build a netconnection ()

var NC = new Netconnection ();

Connection

Nc.connect ("Rtmp://localhost/test1");
How do you know it's not connected? A Onstatus event is triggered when the server is successfully connected
Nc.onstatus = function (info) {
Trace (Info)
Trace (Info.code)
for (i in info) {
Trace (i+ ":" +info);
}
};

Complete code:

var NC = new Netconnection ();
Nc.onstatus = function (info) {
Trace (Info.code);
if (Info.code = = "NetConnection.Connect.Success") {
Trace ("Connected");
}
};
Nc.connect ("Rtmp://localhost/test1");

Note: By default, the server allows you to connect, but only by default, if the server rejects your connection, the above code will not work. What's going on? Let's look at the connection process.
Connection process
Whenever a client attempts to connect to a server, a netconnection.connect (), the server calls Application.onconnect to authenticate whether the client is allowed to connect, and the OnConnect () method returns null Or does not return, it will enter a pending state until either return true in the OnConnect method or execute acceptconnection (client) allows, return False or execute rejectconnection (client) reject, as shown

Server files exist as. ASC, and you can build a MAIN.ASC in the Test1 folder

Application.onconnect=function (client) {
This.rejectconnection (client);
This.acceptconnection (client)
return True
return False
}

This will deny the connection.

The concept of sharing is to allow each SWF that is linked to the server to get the shared data in real time.
One person changes the data, and everyone else can see it. such as chat room speeches.

Shared objects

Share objects, speak English probably you are more familiar ha~ sharedobject, en flash, there are two kinds of sharedobject,local sharedobject (LSO) and remote Sharedobject (RSO), That is, local sharing and remote sharing, we discuss the remote, but before you better to understand the local, good for you ...
RSO is stored as a file on the server side, and the extension is. FSO, why not. RSO?.... I was going to ask.----B.
Code
Initialization RSO need to establish a connection with the server, continuation of the section, we first establish a connection with the server

Initializing a remote share to take advantage of the NC Channel
var mync = new Netconnection ();
Mync.onstatus = function (info) {
if (Info.code = = "NetConnection.Connect.Success") {
Success uses this NC to initialize the RSO
Initrso (this);
}
};

As with the previous code, only after the successful connection to a Initrso () function, do not understand to go back to a section to see
http://www.nshen.net/blog/article.asp?id=394

The bottom is initrso, similar to the connection structure.

function Initrso (NC) {
The Myrso.fso file is established on the server, the 2nd parameter specifies the NC channel, and the 3rd specified file is persisted on the server
My_rso = Sharedobject.getremote ("Myrso", Nc.uri, True);
My_rso.onsync = function (list) {
The list is an array of objects, similar to this [{name: "x", Code: "Success"},{name: "Y", Code: "Success"}]
Initial success
};
My_rso.connect (NC); Connection
}

Well, let's see a complete example below.
To draw an MC called MC, write code on the first frame,

Initializing a remote share to take advantage of the NC Channel
var mync = new Netconnection ();
Mync.onstatus = function (info) {
if (Info.code = = "NetConnection.Connect.Success") {
Success uses this NC to initialize the RSO
Initrso (this);
}
};
Mync.connect ("Rtmp://localhost/test1");
function Initrso (NC) {
My_rso = Sharedobject.getremote ("Myrso", Nc.uri, True);
My_rso.onsync = function () {
Mc._x=this.data.x
Mc._y=this.data.y
};
My_rso.connect (NC);
}
OnMouseDown = function () {
my_rso.data.x = _root._xmouse
MY_RSO.DATA.Y = _root._ymouse
};

Then the release settings are set to allow only the network, publish see now you can open multiple player windows, click one of the other window to see the change, click here to download
(http://www.nshen.net/blog/attachments/200601/11_145320_test3.fla)

Connection process

Finish.

Write another, do not know if this can do online games ~

MYNC = new Netconnection ();
Mync.onstatus = function (info) {
if (Info.code = = "NetConnection.Connect.Success") {
Initrso ();
}
if (Info.code = = "NetConnection.Connect.Closed") {
Trace ("Off");
}
};
function Initrso () {
My_rso = Sharedobject.getremote ("Myrso", Mync.uri, True);
Trace (My_rso);
My_rso.onsync = function () {
mc._x = this.data.hero.x;
};
My_rso.connect (MYNC);
}
Mync.connect ("Rtmp:/my_app/test1");
Mync.connect ("Rtmp://localhost:443/my_app/aaa")
Mc.onenterframe = function () {
my_rso.data.hero.x = this._x;
if (Key.isdown (Key.left)) {
This._x-= 5;
}
if (Key.isdown (key.right)) {
This._x + 5;
}
};

Related Article

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.