Stratus P2P
Adobe Flash 2012. 3. 2. 18:23
http://www.flashrealtime.com/tuts/p2p-in-flash.html
http://blog.jidolstar.com/498
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" minWidth="955" minHeight="600" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
private const SERVER_ADDRESS:String = "rtmfp://stratus.adobe.com/";
private const DEVELOPER_KEY : String = "f70ddb3113ba09838bf22591-9b2e9c305f24";
private var nc: NetConnection;
private var myPeerID:String;
private var farPeerID : String;
//stream
private var sendStream : NetStream;
private var recvStream : NetStream;
private function initConnection():void
{
trace("initConnection");
if( txtFingerprint.text )
{
farPeerID = txtFingerprint.text;
}
nc = new NetConnection();
nc.addEventListener( NetStatusEvent.NET_STATUS, ncStatus);
nc.connect(SERVER_ADDRESS+DEVELOPER_KEY);
}
private function ncStatus(e:NetStatusEvent):void
{
trace( e.info.code );
myPeerID = nc.nearID;
txtFingerprint.text
= myPeerID;
}
private function initSendStream():void
{
trace("initSendStream");
sendStream = new NetStream(nc, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
sendStream.publish("media");
var sendStreamClient : Object = new Object();
sendStreamClient.onPeerConnect = function(callerns:NetStream):Boolean{
farPeerID = callerns.farID;
trace("onPeerConnect: " + farPeerID);
return true;
}
sendStream.client = sendStreamClient;
}
private function initRecvStream():void
{
recvStream = new NetStream(nc, farPeerID);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
recvStream.play("media");
recvStream.client = this;
}
public function receiveSomeData(str:String):void
{
txtReceiveData.text = str;
}
private function sendSomeData():void
{
sendStream.send("receiveSomeData", txtSendData.text);
}
private function netStatusHandler(e:NetStatusEvent):void
{
trace(e.info.code);
}
]]>
</fx:Script>
<mx:TextInput x="39" y="46" width="529" id="txtFingerprint"/>
<mx:Button x="576" y="46" label="Connect" click="initConnection()"/>
<s:TextInput x="39" y="76" width="283" id="txtSendData"/>
<s:Button x="346" y="76" label="Send data" click="sendSomeData()"/>
<s:TextInput x="39" y="104" width="377" id="txtReceiveData"/>
<s:Button x="39" y="132" label="initSendStream" width="133" click="initSendStream()"/>
<s:Button x="204" y="132" label="initReceiveStream" width="164" click="initRecvStream()"/>
</mx:Application>
'Adobe Flash' 카테고리의 다른 글
FDT 5 단축키 (0) | 2012.03.07 |
---|---|
기하도형(Geometry) Point.polar (0) | 2012.03.06 |
Flex spark & mx component (0) | 2012.02.24 |
네이버용 오픈 소셜 SDK (1.2) (0) | 2012.02.15 |
as3corelib.swc (0) | 2012.02.15 |