我爲了使用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事件。它不打印任何連接,如果有任何連接,我不知道爲什麼。 –