FlashMediaServer3.0安装包中
将Samples文件夹(具体路径:Flashmedia3_Int_Strm_ALP/Documentation/Samples)中的所有文件复制到FMS3安装路径下Program Files/Adobe/Flash Media Server 3/applications文件夹中,目的主要是建立服务器端对应的应用程序文件夹和服务端的程序(源文件可以不考,asc文件是必须的)。用户管理和端口号设置和FMS2相同只要修改fms.ini中相应的参数即可。
测试HelloServer实例
客户端代码如下:
package {
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.events.MouseEvent;
public class HelloServer extends MovieClip {
private var nc:NetConnection;
/*
* Constructor.
*/
public function HelloServer() {
// register listeners for mouse clicks on the two buttons
connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
}
/*
* Connect to the server.
*/
public function connectHandler(event:MouseEvent):void {
trace("Okay, let's connect now");
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmp://localhost/HelloServer");
}
/*
* Disconnect from the server.
*/
public function closeHandler(event:MouseEvent):void {
trace("Now we're disconnecting");
nc.close();
}
/*
* Handle events relating to the server connection.
*/
public function netStatusHandler(event:NetStatusEvent):void {
trace("connected is: " + nc.connected);
trace("event.info.level: " + event.info.level);
trace("event.info.code: " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
trace("Congratulations! you're connected" + "/n");
break;
case "NetConnection.Connect.Rejected":
trace ("Oops! the connection was rejected" + "/n");
break;
case "NetConnection.Connect.Closed":
trace("Thanks! the connection has been closed" + "/n");
break;
}
}
}
}
输出结果如下:
连接FMS服务器时
Okay, let's connect now
connected is: true
event.info.level: status
event.info.code: NetConnection.Connect.Success
Congratulations! you're connected
断开服务器时
Now we're disconnecting
connected is: false
event.info.level: status
event.info.code: NetConnection.Connect.Closed
Thanks! the connection has been closed