Categories
Articles

Adobe Peer to Peer Basic Example For Connecting to Stratus Server

By Lon Hosford

This is the bare bones example to set up a Flex application for connecting to the Adobe Stratus Server and obtaining a unique 256-bit peer id.

[ad name=”Google Adsense”]

The peer id is shared with others using the application for communication as well as their peer id shared with you. This example does not go into those steps but basically you need a means to do that such as using the FMS server or any web server.

The Adobe Stratus Server handles the peer id handshaking between the peer to peer members. The data such as video or files are shared directly between he peers. The Adobe Stratus server is free and various bloggers have indicated its future is becoming part of the FMS server product. You can use the Adobe Stratus server by obtaining a developer key at Adobe Labs. Insert that key in the code at line 16.

This is the code for an Air application which can also be used for a Flex application.

.
.
.
<?xml version="1.0" encoding="utf-8"?>
<!-- Bare bones Adobe Stratus P2P connection and retrieval of an id -->
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   creationComplete="creationCompleteHandler(event)">

	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;

			private const SERVER:String = "rtmfp://stratus.adobe.com/";
			private const DEVKEY:String = "{YOUR ADOBE STRATUS DEVELOPER KEY}";
			private var stratusConnection:NetConnection;
			protected function creationCompleteHandler(event:FlexEvent):void
			{
				console("============================================");
				console("This is a bare bones example of connecting ");
				console("to the adobe status peer to peer server ");
				console("and obtaining an id. ");
				console("============================================");
				console("creationCompleteHandler") ;

				stratusConnection = new NetConnection();
				stratusConnection.addEventListener(NetStatusEvent.NET_STATUS, stratusConnectionStatusHandler);
				stratusConnection.connect(SERVER+DEVKEY);
			}

			private function stratusConnectionStatusHandler(event:NetStatusEvent):void{
				console("stratusConnectionStatusHandler - event.info.code:" + event.info.code);

				switch (event.info.code)
				{
					case "NetConnection.Connect.Success":
						console("stratusConnectionStatusHandler - nearID:" + stratusConnection.nearID);
						break;
					case "NetConnection.Connect.Failed":
						console("stratusConnectionStatusHandler - connection failed");
						break;
					default:
						console("stratusConnectionStatusHandler - uncaught event.info.code");
						break;
				}
			}
			private function console(msg:String):void
			{
				trace(msg);
				out_ta.appendText(msg + "\n");

			}

		]]>
	</fx:Script>

	<s:TextArea id = "out_ta"
				width = "100%" height = "100%"
				lineBreak="explicit"
				fontFamily="_typewriter"/>
</s:WindowedApplication>