Flash Communication Server Note 2

Source: Internet
Author: User
Connect to the server

 

To connect to an instance of the FCS, you must use the net netconnection and netconnection. Connect commands in the client script to send the request to the server.
TIPS: You can also use components to connect to the server.

Start the service

If the server is not started, you must start it manually. Choose program> Macromedia Flash Communication Server MX> Start service from the Windows Start Menu. In Windows.
If you are eager to run the service, open the task manager and check whether flashcom.exeand flashcomadmin.exe are in the Process List.
In UNIX, open the shell window, change the directory to the installation directory of the FCS, and enter fcsmgr Server start as a root user.
 
Open a connection to the server

Open a new file in flash and add client script commands to connect to the server.
 
1. Enable a connection in a flash movie:
My_nc = new netconnection ();
2. Run the following command to connect to the server.
My_nc.connect (targeturi );
The above is the basic usage of netconnection. Connect. Targeturi is the URI of an application on the FCS. The format is as follows:
Rtmp: // localhost [: Port]/apname [/InstanceName]
Localhost indicates that the server runs on the local computer.
Rtmp: // host [: Port]/appname [/InstanceName]
Note: The rtmp protocol must be specified. If not specified, Flash Player uses http to connect to the server, causing connection failure.
The following code shows how to connect to the application server.
My_nc: netconnection = new netconnection ();
My_nc.connect ("rtmp: // myserver.mydomain.com/appname/appinstance ");
My_nc = new netconnection ();
My_nc.connect ("rtmp: // myserver.mydomain.com/appname/appinstance ");
 
The FCS Application often needs to publish (broadcast) and play back a stream (file ). After installing the FCS, a fla example is provided:/doc_connect/doc_connect.fla, showing how to transmit video streams between two customers. You can view this example to learn how to connect to the FCS and how to develop stream-based applications.
The doc_connect file shows how to initialize a movie, connect to the server, publish and play a stream. It also explains how to save your example file.
Open the doc_connect.fla file in the./help_collateral/doc_connect directory.
 

View results:
1. Create an application named doc_connect on the server.
2. Open the doc_connect.swf file in the./help_collateral/doc_connectdirectory.
Then we can see two video/audio playback windows, one is the live streaming media obtained from camera, and the other is the playback media released by the server.
In this example, the fcscomponent of flashmx is used. If these components are not installed in flashmx, you can use the following method:
1. Select File> New in flash to create a new file.
2. Create a video object in the database Panel (click the Options menu of the database panel and select new video ).
3. Drag the object to the stage and create two instances of the object named live_video and published_video respectively. Change the published_video size to 200*150;
4. Create a directory named doc_connect on the FCS and create a doc_connect FCS Application. Save the FLA file doc_connect.fla in this directory.
5. Select the first frame of the timeline and open the action Panel (WINDOW> action ).
Note: Make sure that the action is loaded at the first frame instead of an object on the stage.
6. Obtain the default camera (CAMERA) and load it to the live_video video object.
Client_cam = camera. Get ();
Live_video.attachvideo (client_cam );

Create a function to connect to the FCS, use trace to check whether the connection is successful, and open an instance named room_1 in the doc_connect application. Remember, you must specify the Real-Time messaging protocol (rtmp ).
Function doconnect (){

Client_nc = new netconnection ();
Client_nc.onstatus = function (Info ){
Trace ("level:" + info. Level + "Code:" + info. Code );
}
Client_nc.connect ("rtmp: // localhost/doc_connect/room_01 ");

}
NOTE: If your SWF and FCS run on the same computer, you can use the rtmp: // localhost/doc_connect/test abbreviation rtmp:/doc_connect/test to establish a connection. In this way, you can move this file to different servers without changing your code. However, if your flashmx and FCS are no longer on the same machine, you must specify the server URL.
Create a network stream named out_ns for video, load camera to this stream, and publish this stream as myteststream. All these steps are completed in the publishme function.
Function publishme (){

Out_ns = new netstream (_ root. client_nc );
Out_ns.attachvideo (client_cam );
Out_ns.publish ("myteststream ");

}
Note: out_ns.publish ("myteststream") omitting a parameter: howtopublish. If you do not assign a value to this parameter, the server will automatically publish the stream as live ("live broadcast", without saying that the stream record is published on the server)
Create a stream in_ns in the playme function, connect to the netconnect client, and let the published_video object load stream and play the stream in_ns.
Function playme (){

In_ns = new netstream (_ root. client_nc );
Published_video.attachvideo (in_ns );
In_ns.play ("myteststream ");

}
6. Write the following command to call the function just created.
// Connect to the server
Doconnect ();

// Publish live stream
Publishme ();

// Play back the stream published by the server
Playme ();
7 save the file.
Save the file.
 
Test this example
1 choose File> Publish settings, select Flash and HTML, click Publish, and then click OK.
1. Select File> release settings, select Flash and HTML, click release, and then click OK.
2 choose control> test movie.
Select Control> test movie
You will see two video windows on the stage and the same image is displayed. Haha.
3. To view data in a browser, choose File> release preview> default, or press Ctrl + F12.

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.