0

为了使用 RTMFP,我在 ActionScript 中编写了一些基本函数:

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/ ) 运行良好。

我遵循的程序:

  • 在应用程序 1 上初始化 NC。(发送方)
  • 在应用程序 2 上初始化 NC。(接收方)
  • 我将远端对等 id 复制到应用程序 2。并运行 receveInit。
  • 我在应用程序 1 上初始化发送流 (sendInit)。

注意:我试图扭转最后两个过程,无论哪种方式都不起作用。

在此之后,我执行 sendMessage() 从toSendText.text.

不工作。为什么?我的代码有什么问题?

提前感谢您提供的每一个有用的答案。

4

3 回答 3

1

因为 cc.rtmfp.net 是连接检查器,而不是 P2P 引入服务(p2p.rtmfp.net)。cc 执行一些快速测试,发送结果,然后断开连接。它不执行任何其他功能,也不提供任何其他服务。

于 2013-02-02T19:22:42.653 回答
0

我发现。

对于开发和测试,我使用 Mac 并在那里测试了应用程序。不工作。还是不行。在 Windows 上,它可以完美运行。

奇怪的。

于 2013-02-06T05:33:01.597 回答
0

您必须为receiveMessage(). 否则它只是一个你必须调用它的函数。

于 2017-01-20T16:54:09.670 回答