0

我正在使用 Adob​​e Cirrus 在 Flash 播放器通信器中编写语音聊天。我无法处理通过本地网络连接两个 Flash 播放器的问题。我有带有已编译 SWF 文件 (192.168.1.2:8080/evm_server/bin) 的 tomcat 服务器。当我在本地计算机 (192.168.1.2) 上打开此 SWF 文件时,一切正常。我可以登录并调用在网络中其他计算机上登录的客户端,但是当我尝试在另一台计算机上登录并调用 192.168.1.2 时没有任何反应(没有警报显示,但它应该)。这是通信组件的代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx"
           xmlns:components="pl.rafalo235.evm_client.components.*"
           show="initGroup(event)"
           creationComplete="initApp(event)">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <mx:HTTPService id="friendsService"
            method="POST"
            url="{EVMServerConnection.SERVER_ADDRESS}/friends"
            result="friendsService_resultHandler(event)"
            fault="friendsService_faultHandler(event)">
        <mx:request>
            <login>{userAccount.login}</login>
            <password>{password}</password>
        </mx:request>
    </mx:HTTPService>

    <mx:HTTPService id="setPeerIdService"
            method="POST"
            url="{EVMServerConnection.SERVER_ADDRESS}/peerId"
            result="peerIdService_resultHandler(event)"
            fault="peerIdService_faultHandler(event)">
        <mx:request>
            <login>{userAccount.login}</login>
            <password>{password}</password>
            <peerId>{myPeerId}</peerId>
            <a>1</a>
        </mx:request>
    </mx:HTTPService>

    <mx:HTTPService id="clearPeerIdService"
            method="POST"
            url="{EVMServerConnection.SERVER_ADDRESS}/peerId"
            result="peerIdService_resultHandler(event)"
            fault="peerIdService_faultHandler(event)">
        <mx:request>
            <login>{userAccount.login}</login>
            <password>{password}</password>
            <a>0</a>
        </mx:request>
    </mx:HTTPService>
</fx:Declarations>

<fx:Script>
    <![CDATA[
    import flash.events.Event;
    import flash.media.Microphone;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import mx.collections.ArrayCollection;
    import mx.collections.ArrayList;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    import pl.rafalo235.evm_client.data.Account;
    import mx.events.FlexEvent;
    import pl.rafalo235.evm_client.data.Friend;
    import pl.rafalo235.evm_client.events.CallButtonClickEvent;
    import flash.events.NetStatusEvent;
    import mx.controls.Alert;
    import pl.rafalo235.evm_client.net.CirrusServerConnection;
    import pl.rafalo235.evm_client.net.EVMServerConnection;
    import pl.rafalo235.evm_client.events.CirrusServerConnectionEvent;

    [Bindable]
    public var applicationRoot:Main;

    [Bindable]
    public var userAccount:Account;

    [Bindable]
    public var friendsList:ArrayCollection = new ArrayCollection();

    [Bindable]
    private var password:String;


    public function initApp(event:FlexEvent):void {
        friendsListUI.addEventListener(CallButtonClickEvent.CALL_BUTTON_CLICK, onCallButtonClick);
    }

    public function initGroup(event:FlexEvent):void {
        initNetConnection();
        friendsService.send();
    }

    public function destructGroup():void {
        clearPeerIdService.send();
        userAccount = null;
        friendsList.removeAll();
        password = null;
    }

    public function setPassword(password:String):void {
        this.password = password;
    }

    public function friendsService_resultHandler(event:ResultEvent):void {
        if (event.result.friends != null) {
            if (event.result.friends.friend is ArrayCollection) {
                var eventData:ArrayCollection = ArrayCollection(event.result.friends.friend);
                var tmpFriend:Friend = null;

                for each (var eventDataItem:Object in eventData) {
                    tmpFriend = new Friend(eventDataItem);
                    friendsList.addItem(tmpFriend);
                    tmpFriend = null;
                }
            } else {
                friendsList.addItem(new Friend(event.result.friends.friend));
            }
        }
    }

    public function friendsService_faultHandler(event:FaultEvent):void {

    }

    public function switchAuthenticationView(event:MouseEvent):void {
        destructGroup();
        applicationRoot.currentState = "default";
    }

    public function onCallButtonClick(event:Event):void {
        var e:CallButtonClickEvent = CallButtonClickEvent(event);
        connectToPeer(e.friend.peerId);
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~private

    [Bindable]
    private var cirrusServerConnection:CirrusServerConnection;

    private const SERVER_ADDRESS:String = "rtmfp://p2p.rtmfp.net/";
    private const DEVELOPER_KEY:String = "f3161a7e23cab7eeae9ea32d-fe63c3b19868";

    private var netConnection:NetConnection;

    [Bindable]
    private var myPeerId:String;
    private var farPeerID:String;

    private var sendStream:NetStream;
    private var recvStream:NetStream;

    private var mic:Microphone;

    private function initNetConnection():void {
        //cirrusServerConnection = new CirrusServerConnection();
        //cirrusServerConnection.addEventListener(CirrusServerConnectionEvent.CONNECTED, openSendStream);
        //cirrusServerConnection.connect();
        netConnection = new NetConnection();
        netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        netConnection.connect(SERVER_ADDRESS + DEVELOPER_KEY);

        if (Microphone.isSupported) {
            mic = Microphone.getMicrophone();
            mic.rate = 11;
            mic.setUseEchoSuppression(true);
            mic.gain = 50;
            mic.setSilenceLevel(20);
        }
    }

    private function netStatusHandler(event:NetStatusEvent):void {
        trace("CirrusConnection: " + event.info.code);
        Alert.show("CirrusConnection: " + event.info.code);
        switch(event.info.code) {
            case "NetConnection.Connect.Success":
                myPeerId = netConnection.nearID;
                openSendStream();
                break;
            case "NetStream.Play.Start":
                break;
        }
    }

    private function sendStreamStatusHandler(event:NetStatusEvent):void {
        trace("SendStream: " + event.info.code);
        Alert.show("SendStream: " + event.info.code);
        switch(event.info.code) {
            case "NetStream.Publish.Start":
                setPeerIdService.send();
                break;
            case "NetStream.Play.Start":
                if (Microphone.isSupported) {
                    sendStream.attachAudio(mic);
                } else {
                    Alert.show("Microphone not supported");
                }
                break;
        }
    }

    private function recvStreamStatusHandler(event:NetStatusEvent):void {
        trace("RecvStream: " + event.info.code);
        Alert.show("RecvStream: " + event.info.code);
        switch(event.info.code) {
            case "NetConnection.Connect.Success":
                break;
            case "NetStream.Play.Start":
                recvStream.receiveAudio(true);
                break;
        }
    }

    private function openSendStream():void {
        var sendStreamClient:Object = new Object();
        sendStreamClient.onPeerConnect = function(callerns:NetStream):Boolean {
            trace("peerConnected");
            if (!Boolean(farPeerID)) {
                connectToPeer(callerns.farID);
            }
            return true;
        }

        sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
        sendStream.addEventListener(NetStatusEvent.NET_STATUS, sendStreamStatusHandler);
        sendStream.client = sendStreamClient;
        sendStream.publish("media");
    }

    public function connectToPeer(id:String):void {
        farPeerID = id;
        recvStream = new NetStream(netConnection,farPeerID);
        recvStream.addEventListener(NetStatusEvent.NET_STATUS, recvStreamStatusHandler);
        recvStream.client = this;
        recvStream.play("media");
    }

    public function peerIdService_resultHandler(event:ResultEvent):void {

    }

    public function peerIdService_faultHandler(event:FaultEvent):void {

    }

    ]]>
</fx:Script>

<s:DataGroup id="friendsListUI" 
            dataProvider="{friendsList}"
                itemRenderer="pl.rafalo235.evm_client.components.FriendItemRenderer"
            x="25" y="25"
            width="200" height="550">

    <s:layout>
        <s:VerticalLayout />
    </s:layout>

</s:DataGroup>

<components:LinkButton x="700" y="25"
        label="Logout" 
        skinClass="pl.rafalo235.evm_client.skins.LinkButtonSkin"
        click="switchAuthenticationView(event)" />

</s:Group>

我通过 Java 服务器 (192.168.1.2:8080/evm_server) 在数据库上发布和获取其他 peerId。也许重要的是只有 192.168.1.2 连接了麦克风。我将不胜感激快速帮助。预先感谢您。

4

1 回答 1

0

问题出在防火墙配置中。当我关闭它时,问题就消失了。

于 2013-01-19T14:06:19.870 回答