两台设备之间的 LAN 不工作

LAN between two devices not working

我编写了一个简单的 AS3 程序来创建不同设备之间的无服务器 P2P LAN 连接。这是它的要点:

客户:

private function initLan():void 
    {
        //G is a class with two static variables - netConnection and netGroup
        G.netConnection = new NetConnection();
        G.netConnection.addEventListener(NetStatusEvent.NET_STATUS, setupLAN);
        G.netConnection.connect("rtmfp:");
    }

    private function setupLAN(e:NetStatusEvent):void
    {
        trace(e.info.code);
        switch (e.info.code)
        {
            case "NetGroup.Connect.Failed": 
            case "NetGroup.Connect.Rejected": 
            case "NetConnection.Connect.Rejected": 
            case "NetConnection.Connect.Failed": 
                trace("There was a problem :/\n+" + e.info.code);
                break;

            case "NetConnection.Connect.Success": 
                trace("Setting up LAN group..");
                setupGroup();
                break;

            case "NetGroup.Connect.Success": 
                trace("LAN group successful!");

                //Start bind requests
                beginBindRequests();

                break;

            case "NetGroup.SendTo.Notify":
                var msg:Object = e.info.message;

                if (msg.type == "BIND RESPONSE") {
                    endBindRequests(); //See beginBindRequests();
                    G.netConnection.removeEventListener(NetStatusEvent.NET_STATUS, setupLAN);
                    G.netGroup.removeEventListener(NetStatusEvent.NET_STATUS, setupLAN);

                    //Connection established.
                }

                break;
        }
    }

    private function setupGroup():void
    {
        var groupspec:GroupSpecifier = new GroupSpecifier("LAN CONNECTION");
        groupspec.postingEnabled = true;
        groupspec.routingEnabled = true;
        groupspec.ipMulticastMemberUpdatesEnabled = true;
        groupspec.addIPMulticastAddress("225.225.0.1:30303");

        G.netGroup = new NetGroup(G.netConnection, groupspec.groupspecWithAuthorizations());
        G.netGroup.addEventListener(NetStatusEvent.NET_STATUS,setupLAN);
    }

    private function beginBindRequests():void 
    {
        function requestBind():void {
            G.netGroup.sendToAllNeighbors( { type:"BIND REQUEST" } );
        }

        //Code running requestBind() until endBindRequests() is called
    }

服务器:

private function initLAN():void
    {
        //G is a class with two static variables - netConnection and netGroup
        G.netConnection = new NetConnection();
        G.netConnection.addEventListener(NetStatusEvent.NET_STATUS, setupLAN);
        G.netConnection.connect("rtmfp:");
    }

    private function setupLAN(e:NetStatusEvent):void
    {
        switch (e.info.code)
        {
            case "NetGroup.Connect.Failed": 
            case "NetGroup.Connect.Rejected": 
            case "NetConnection.Connect.Rejected": 
            case "NetConnection.Connect.Failed": 
                trace("There was a problem :/\n+" + e.info.code);
                break;

            case "NetConnection.Connect.Success": 
                trace("Setting up LAN group..");
                setupGroup();
                break;

            case "NetGroup.Connect.Success": 
                trace("LAN group successful!");

                //Add hot controller function
                G.netConnection.addEventListener(NetStatusEvent.NET_STATUS, bindResponses);
                G.netGroup.addEventListener(NetStatusEvent.NET_STATUS, bindResponses);

                G.netGroup.removeEventListener(NetStatusEvent.NET_STATUS, setupLAN);
                G.netConnection.removeEventListener(NetStatusEvent.NET_STATUS, setupLAN);
                break;
        }
    }

    private function setupGroup():void
    {
        var groupspec:GroupSpecifier = new GroupSpecifier("LAN CONNECTION");
        groupspec.postingEnabled = true;
        groupspec.routingEnabled = true;
        groupspec.ipMulticastMemberUpdatesEnabled = true;
        groupspec.addIPMulticastAddress("225.225.0.1:30303");

        G.netGroup = new NetGroup(G.netConnection,groupspec.groupspecWithAuthorizations());
        G.netGroup.addEventListener(NetStatusEvent.NET_STATUS, setupLAN);
    }

    private function bindResponses(e:NetStatusEvent):void
    {
        detailText.text = e.info.code;
        switch (e.info.code)
        {
            case "NetGroup.SendTo.Notify":
                if (e.info.message.type == "BIND REQUEST")
                {
                    //Send bind response
                    G.netGroup.sendToNearest({type: "BIND RESPONSE"}, e.info.from);
                }
                break;
        }
    }

当 运行 编译的 swfs 的两个实例在同一台 PC 中时,这工作正常,但当客户端 运行 在,例如 phone (与 AIR 打包 - 是的,<uses-permission android:name="android.permission.INTERNET" /> 已设置)并且服务器在 PC 上 运行(也是 AIR 应用程序)。
setupLan() 处跟踪 e.info.code 表明,当在不同的设备中时,这两个实例甚至不会 "see" 彼此(NetGroup.Neighbor.Connect 永远不会被触发)。 编辑: 我已经测试过,两台电脑 运行 client/server AIR 应用程序也看不到对方。
最糟糕的部分是相同的代码(尽管在不同的 FlashDevelop 项目中)曾经有效,表明它有效。不知何故。我绝对感到困惑和沮丧。帮助。请。


PS。如果可能(我开始怀疑不是),不涉及干预 router/firewall 设置的解决方案将不胜感激,因为大多数最终用户不会去那个程度使用应用程序。另外,我测试了两个不同的路由器,问题依然存在。

原来问题出在计算机本身,而不是编码或部署。 LAN 正在正确创建,只是在错误的网络上。按照 this link 中的步骤解决了问题。