2011-08-27 15 views
0

不使用Flash Media Server或其他媒體服務器進行Flash。如何直接發送點對點數據包?我們可以從一個點直接發送數據包到另一個嗎?如何製作Flash IP到IP應用程序,用於發送媒體?

我已經嘗試過使用Red5,並意識到通過涉及媒體服務器在中間進行數據包交換質量是非常可怕的。

追問: P2PChatLocal.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="connect()"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

    <fx:Script> 
     <![CDATA[   
      private var nc:NetConnection; 
      private var group:NetGroup; 

      [Bindable] 
      private var userName:String; 

      [Bindable] 
      private var connected:Boolean = false; 

      private function connect():void{ 
       nc = new NetConnection(); 
       nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus); 
       nc.connect("rtmfp:"); 

       userName = "user"+Math.round(Math.random()*1000); 
      } 

      private function netStatus(event:NetStatusEvent):void{ 
       writeText(event.info.code); 

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

        case "NetGroup.Connect.Success": 
         connected = true; 
         break; 

        case "NetGroup.Posting.Notify": 
         receiveMessage(event.info.message) 
         break; 
       } 
      } 

      private function setupGroup():void{ 
       var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/groupOne"); 
       groupspec.postingEnabled = true; 
       groupspec.ipMulticastMemberUpdatesEnabled = true; 
       groupspec.addIPMulticastAddress("225.225.0.1:30303"); 

       group = new NetGroup(nc,groupspec.groupspecWithAuthorizations()); 
       group.addEventListener(NetStatusEvent.NET_STATUS,netStatus); 
      } 

      private function sendMessage(txt:String):void{ 
       var message:Object = new Object(); 
       message.text = txt; 
       message.sender = group.convertPeerIDToGroupAddress(nc.nearID); 
       message.userName = txtUser.text; 

       group.post(message); 

       receiveMessage(message); 
      } 

      public function receiveMessage(message:Object):void{ 
       writeText(message.userName+": "+message.text); 
      } 

      private function writeText(txt:String):void{ 
       txtHistory.text += txt+"\n"; 
      } 

      protected function btnSend_clickHandler(event:MouseEvent):void 
      { 
       sendMessage(txtMessage.text); 
      } 

     ]]> 
    </fx:Script> 
    <s:TextInput text="{userName}" x="10" bottom="10" id="txtUser"/> 
    <s:TextInput left="146" right="88" bottom="10" id="txtMessage" enter="btnSend_clickHandler(null)"/> 
    <s:TextArea left="10" right="10" top="75" bottom="40" id="txtHistory"/> 
    <s:Button enabled="{connected}" label="Send" bottom="10" right="10" click="btnSend_clickHandler(event)" id="btnSend"/> 


</s:Application> 

回答

2

是的,這是可能的

首先來看看Cirrus;這是Adobe的解決方案。它使用實時媒體流協議(RTMFP);我相信這是在Flash Player 10/AIR 2中引入的。

如果你google了其他幾個選項。這裏是one tutorial

+0

謝謝。所以我更新了我的上述帖子。那是做點對點的代碼嗎? (是的,它是一個樣本,但這樣你們進行媒體交流,聽起來很酷)。 – YumYumYum

+0

你能用上面的代碼參考來做全雙工嗎? – YumYumYum

+0

@ IamSon0fRaja既然你說「你們夥計們」,我想指出我個人並沒有做任何事情w /閃爍P2P功能。那裏的職位/資源我無法獲得任何獎勵。這是有趣的東西,但與我目前的項目無關。 – JeffryHouser

相關問題