kolnedra . com | Adobe Stratus with Flash CS4 IDE

Adobe Stratus with Flash CS4 IDE

Adobe Stratus with Flash CS4 IDE

Date: 4 March 2010

"Adobe® Stratus 2 enables peer assisted networking using the Real Time Media Flow Protocol (RTMFP) within the Adobe Flash® Platform. RTMFP is the evolution of media delivery and real time communication over the Internet enabling peers on the network to assist in delivery. Stratus was first introduced in 2008 as a rendezvous-only service that allowed clients to send data from client to client without passing through a server. Adobe Flash Player 10, which debuted peer assisted networking, has been adopted today by over 90% of all internet connected PCs."
With adobe launching it's RTFMP network called Stratus the first tutorials and beta reviews appeared online, only all of them were written for Flex. So here is a small tutorial on how to set up a RTFMP peer-to-peer connection using only Flash CS4 and the latest 10.1 runtime.

- Example (Connecting takes same time, be patient)
- Download source

Setting up

- Buy (or download a trial) Adobe Flash CS4
- Download Flash Player 10.1 SWC (scroll down)
- Sign up for a beta developer key
- You might want to read this article about Adobe Stratus 2

1. Browse to the following folder: (OSX) /Applications/Adobe Flash CS4/Common/Configuration/ActionScript 3.0/FP10 or (PC): C:\Program Files\Adobe\Adobe Flash CS4\Common\Configuration\ActionScript 3.0\FP10
2. Make a backup of playerglobal.swf
3. Copy the downloaded playerglobal.swf to the directory from step 1 4. And you're done, now you can use Flash Player 10.1 capabilities in your browser (IN YOUR BROWSER ONLY)

Set up a new .fla

import flash.net.NetGroup;

// Constants
const SERVER:String = 'rtmfp://stratus.adobe.com/';
const DEVKEY:String = 'YOUR_API_KEY';

// Variable declarations
var netConnection:NetConnection;
var netGroup:NetGroup;
var netStream:NetStream;
var user:String;
var sNum:int = 0;
A NetConnection, NetGroup (new in 10.1) and a NetStream should be declared in order to succesfully connect and use the RTMFP connection, now establish a new NetConnection:
// Connect to stratus
function connect():void{
	netConnection = new NetConnection();
	netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
	netConnection.connect(SERVER + DEVKEY);	
}
Once the NetConnection is succesfully established it will call the netStatusHandler function
// Receive netStatus events
function netStatusHandler(e:NetStatusEvent):void {
	switch (e.info.code) {
		case 'NetConnection.Connect.Success':
			setupGroup();
		break;
		case 'NetGroup.Posting.Notify':
			receiveMessage(e.info.message);
		break;
	}
}
Once the NetConnection is successfully established we can set up a new NetGroup
// Set up the NetGroup and NetStream
function setupGroup():void {
	// Create new GroupSpecifier
	var groupspec:GroupSpecifier = new GroupSpecifier('kolnedra_stratus/g1');
	groupspec.serverChannelEnabled = true;
	groupspec.postingEnabled = true;
	
	// Create new NetStream
	netStream = new NetStream(netConnection, groupspec.groupspecWithAuthorizations());
	netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
 
 	// Create new NetGroup
	netGroup = new NetGroup(netConnection, groupspec.groupspecWithAuthorizations());
	netGroup.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
 
 	// Create a random user
	user = 'user' + int(Math.random() * 10000);
}
Everything is set up, now the only thing you have to do is listening for upcoming messages and send them yourself
/** Receive
 * @param $msg Object {user, text, sender, sequence}
**/
function receiveMessage($msg:Object):void{
	trace('<' + $msg.user + '>', $msg.text);
}

/** Sending and receiving messages
 * @param $line String The message to post
 * @usage sendMessage("Hello world");
**/
function sendMessage($line:String):void {
	var msg:Object = {
		sender: 	 netConnection.nearID,
		user:		user,
		text:		$line,
		sequence:    ++sNum
	};
	netGroup.post(msg);
	receiveMessage(msg);
}

Recap

This may be a lot to swallow at once, so you can download my example here and you can see the result here (connecting takes same time, be patient), you might want to open 2 different browser windows to test it out.
If you receive "NetGroup.Neighbor.Connect" another user is connected to the NetGroup and you can chat with each other

Comments

Hi,
When i am trying this i got a error mesage as : Definition flash.net:NetGroup could not be found.How can i rectify this problem.And also i have one more doubt is there to set globalplayer.swf path any where in the code.

2010-03-06 06:10:00 Divyareddy http://

@Divyareddy:
The new flashplayer update only works in a browser window, it doesn't work when you publish in flash IDE (CTRL + ENTER or F12)

2010-03-08 17:15:36 KolNedra http://www.kolnedra.com

4444

2010-04-26 23:04:06 Ilay http://divisionby0.org

Hi
I tryed to do Flex example for simple chat (p2p) with Stratus at Flash CS4 IDE
(adapted it of course) but onPeerConnect Event does not fire.

2010-04-26 23:04:43 ilay http://

Can you take a look at my code ? What's wrong with it ?

2010-04-26 23:05:10 Ilay http://

here is the link divisionby0.org/stratus_test/stratusTest.zip

2010-04-26 23:06:01 Ilay http://

i have 3 input texts: MY_peerIDText, txtSendData, txtReceiveData When i press connectToStratusBTN i get ID after than i open another browser window with the same swf and paste this ID into MY_peerIDText After connection i press initSendStreamBTN in first swf (it is 1st browser page) and i press initReceiveStreamBTN in 2nd swf After that iwrite down some text in txtSendData TextField (in 1st browser page) and press sendDataBTN Nothing happens :)

2010-04-26 23:07:09 Ilay http://

Cool, thanks' for posting, would be nice to have an actionscript source file though, not flash. But thanks, I didn't realize there was a netGroup or GroupSpecifier class

2010-11-07 01:58:38 FunkyDude http://

Thanks so much. This is exactly what i was looking for. Helped a lot.

2011-06-11 11:10:39 venkatnarayan http://