In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Local P2P Conn test

reading http://www.flashrealtime.com/local-flash-peer-to-peer-communication-over-lan-without-stratus/ and trying this out
Get Adobe Flash player
by mash 17 Sep 2010
/**
 * Copyright mash ( http://wonderfl.net/user/mash )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vlLP
 */

// non done yet...

package {
    import flash.text.TextField;
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.system.*;
    import com.bit101.components.*;
    public class FlashTest extends Sprite {
        private var nc :NetConnection;
        private var group :NetGroup;
        private var myname :String;
        
        private var input :InputText;
        private var button :PushButton;
        public function FlashTest() {
            Security.allowDomain('*');
            
            tf = new TextField;
            tf.width = 465;
            addChild(tf);
            log("initialized");

            var FlashVars:Object = loaderInfo.parameters;
            myname = FlashVars["viewer.displayName"];
            log("hi, "+myname);
            
            input = new InputText(this, 200, 0, "", null);
            button = new PushButton(this, 300, 0, "push", function() :void {
                log("pushed input: "+input.text);
                
                sendMessage( input.text );
            });

            connect();
            
        }

        private function connect():void{
            nc = new NetConnection();
            nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
            nc.connect("rtmfp:");
            log("connecting");
        }
 
        private function netStatus(event:NetStatusEvent):void{
            log("[netStatus]code: "+event.info.code);
            switch(event.info.code){
            case "NetConnection.Connect.Success":
                setupGroup();
                break;
            case "NetGroup.Posting.Notify":
                log(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{
            log("sending :"+txt);
            
            var message:Object = new Object();
            message.text = txt;
            message.sender = group.convertPeerIDToGroupAddress(nc.nearID);
            message.userName = myname; // flashvars["viewer.displayName"]
                
            group.post(message);
        }

    
    }
}

import flash.text.*;
var tf :TextField;
function log(str :String) :void {
    tf.appendText(str + "\n");
}