是什么阻碍了 NetStream.onPeerConnect 被触发?

发布于 2024-10-05 09:37:53 字数 1498 浏览 3 评论 0原文

我正在使用 Adob​​e Stratus(现已重命名为 Cirrus)来构建 p2p 应用程序。在应用程序内部,我使用了 NetStream.onPeerConnect 回调函数,并期望每次连接对等点时都会触发它。然而,我的朋友 A 总是失败,而奇怪的是,朋友 B 却成功地调用了该函数,没有任何问题。

我想知道这个问题的原因可能是什么?

以下是代码片段的样子。

首先,创建一个NetConnection

netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER_ADDRESS+DEVELOPER_KEY);

其次,在NetConnection连接成功后创建NetStream

private function netConnectionHandler(event:NetStatusEvent):void{

    switch (event.info.code){
        case "NetConnection.Connect.Success":

            sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
            sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);

            var sendObj:Object = new Object();
            sendObj.onPeerConnect = function(subscriber:NetStream) : Boolean {

                trace("[onPeerConnect] far id: " + subscriber.farID);
                return true;
            } 
            sendStream.client = sendObj;
            sendStream.publish("file");
            ......

第三,这是我如何在两个同伴之间建立联系的方法,

    receivedStream = new NetStream(netConnection, farId);
    receivedStream.client = this;
    receivedStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
    receivedStream.play("file");

请帮助启发我。谢谢!

I'm using Adobe Stratus (now renamed to Cirrus) to build a p2p application. Inside the application, I used NetStream.onPeerConnect callback function and expected it to be triggered every time when a peer is connected. However, it always failed with my friend A while strangely friend B managed to have the function called without any problem.

I was wondering what could be the cause to this issue?

Here are how the code pieces look like.

First of all, create a NetConnection.

netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER_ADDRESS+DEVELOPER_KEY);

Secondly, create NetStream upon NetConnection successfully connected.

private function netConnectionHandler(event:NetStatusEvent):void{

    switch (event.info.code){
        case "NetConnection.Connect.Success":

            sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
            sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);

            var sendObj:Object = new Object();
            sendObj.onPeerConnect = function(subscriber:NetStream) : Boolean {

                trace("[onPeerConnect] far id: " + subscriber.farID);
                return true;
            } 
            sendStream.client = sendObj;
            sendStream.publish("file");
            ......

Thirdly, here's how I build the connection between two peers

    receivedStream = new NetStream(netConnection, farId);
    receivedStream.client = this;
    receivedStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
    receivedStream.play("file");

Please help enlighten me. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏辞 2024-10-12 09:37:53

原来我的朋友 A 位于对称 NAT 后面。我正在考虑为我们设置一个 TURN 服务器来建立成功的连接。

It turns out my friend A is behind a symmetric NAT. I'm thinking to setup a TURN server for us to build a successful connection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文