【问题标题】:Why is rtmfp not working with these parameters and functions?为什么 rtmfp 不能使用这些参数和函数?
【发布时间】:2013-01-17 16:31:57
【问题描述】:

为了使用 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 根据远端对端初始化传入流 我复制粘贴到incomingID.text的id
  • 我将每个结果打印到receivedMessages.text
  • 我没有防火墙,也没有 NAT。
  • Adobe 示例应用程序 (http://labs.adobe.com/technologies/cirrus/samples/) 完美运行。

我遵循的程序:

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

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

在此之后,我执行 sendMessage() 从toSendText.text 读取消息。

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

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

【问题讨论】:

  • 可能是因为你的时间不对?这些连接是基于事件的。您需要侦听 NetStream.Play.Start 以了解其他用户已成功连接到您发布的流,然后您才能使用 sendMessage() 在该流上发送任何内容。还有许多其他状态事件会触发连接和流,您应该查看NetStatusEvent codes
  • 谢谢。 incomingStreamHandler 将打印出在incomingStream 上触发的evert 事件。它在连接时没有打印出任何东西,如果有任何连接,我不知道为什么。

标签: apache-flex actionscript netstream rtmfp


【解决方案1】:

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

【讨论】:

  • 我同意他的看法。使用 p2p.rtmfp.net 而不是 cc.rtmfp.net
【解决方案2】:

我发现了。

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

奇怪。

【讨论】:

    【解决方案3】:

    您必须为receiveMessage() 添加处理程序。否则它只是一个你必须调用它的函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多