我为了使用RTMFP写了一些基本的功能在ActionScript:为什么rtmfp不能使用这些参数和功能?
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.ui.Keyboard;
private var serverAddress:String = "rtmfp://cc.rtmfp.net/";
private var serverKey:String = "xxxxx";
private var netConnection:NetConnection;
private var outgoingStream:NetStream;
private var incomingStream:NetStream;
private function initConnection():void {
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(serverAddress + serverKey);
}
private function netConnectionHandler(event:NetStatusEvent):void {
receivedMessages.text += "NC Status: " + event.info.code + "\n";
//Some status handling will be here, for now, just print the result out.
switch (event.info.code) {
case 'NetConnection.Connect.Success':
receivedMessages.text += "My ID: " + netConnection.nearID + "\n";
break;
}
}
private function sendInit():void {
outgoingStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
outgoingStream.addEventListener(NetStatusEvent.NET_STATUS, outgoingStreamHandler);
outgoingStream.publish("media");
var sendStreamObject:Object = new Object();
sendStreamObject.onPeerConnect = function(sendStr:NetStream):Boolean {
receivedMessages.text += "Peer Connected ID: " + sendStr.farID + "\n";
return true;
}
outgoingStream.client = sendStreamObject;
}
private function receiveInit():void {
receivedMessages.text += "Initializing Receiving Stream: " + incomingID.text + "\n";
incomingStream = new NetStream(netConnection, incomingID.text);
incomingStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
incomingStream.play("media");
incomingStream.client = this;
}
public function receiveMessage(message:String):void {
receivedMessages.text += "Received Message: " + message + "\n";
}
private function outgoingStreamHandler(event:NetStatusEvent):void {
receivedMessages.text += "Outgoing Stream: " + event.info.code + "\n";
}
private function incomingStreamHandler(event:NetStatusEvent):void {
receivedMessages.text += "Incoming Stream: " + event.info.code + "\n";
}
private function sendMessage():void {
outgoingStream.send("receiveMessage", toSendText.text);
}
private function disconnectNetConnection():void {
netConnection.close();
netConnection.removeEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection = null;
}
private function disconnectOutgoing():void {
outgoingStream.close();
outgoingStream.removeEventListener(NetStatusEvent.NET_STATUS, outgoingStreamHandler);
outgoingStream = null;
}
private function disconnectIncoming():void {
incomingStream.close();
incomingStream.removeEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
incomingStream = null;
}
initConnection
初始化NC,sendInit
初始化发送 流,receiveInit
初始化基础上,远远同行 ID传入的流,我复制粘贴到incomingID.text
- 我打印每个结果到
receivedMessages.text
- 我没有防火墙,也没有NAT。
- Adobe的示例应用程序 (http://labs.adobe.com/technologies/cirrus/samples/)完美的作品。
过程我遵循:
- 初始化NC上应用1(发送者)
- 初始化NC上应用2(接收器)
- 我远节点ID复制到应用程序2 。并运行receveInit。
- 我上应用初始化所述发送流(sendInit)1.
注:我试图扭转最后2过程,doesent工作无论哪种方式。
在此之后,我执行的sendMessage(),其读取从toSendText.text
该消息。
不起作用。为什么? 我的代码有什么问题?
感谢您提前每个有用的答案。
也许是因为你的时间关闭了?这些连接是基于事件的。您需要监听NetStream.Play.Start,以知道其他用户已成功连接到已发布的流,然后才能使用sendMessage()在该流上发送任何内容。还有很多其他状态事件会触发连接和流,您应该查看[NetStatusEvent代码](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/NetStatusEvent.html ) –
谢谢。 incomingStreamHandler将输出incomingStream上触发的evert事件。它不打印任何连接,如果有任何连接,我不知道为什么。 –