Universal Messaging 9.7 | Universal Messaging Developer Guide | Web Client APIs | Web Developer's Guide for Adobe Flex | Examples | Flex Example : Peer to Peer Echo Application
 
Flex Example : Peer to Peer Echo Application
A Sample Adobe Flex Peer to Peer Echo Client
The code shown below is a exert of the echo client, it is the Universal Messaging portion of a echo application.

import com.pcbsys.nirvana.client.*;
import com.pcbsys.nirvana.client.p2p.*;

private var mySession:nSession;
private var factory:nServiceFactory;
private var myNick:String = "";
private var myService:nEventService;

private function startTest():void
{
var completeString:String = "nhp://127.0.0.1:80";
var appName:String = "Universal MessagingFlexP2PEchoClient";
try {
var attributes:nSessionAttributes =
new nSessionAttributes(completeString, 5);
mySession = nSessionFactory.create(attributes, "subject", appName, errorCB);
mySession.init(sessionInitCB, this);
}
catch(e:SecurityError) {
}
}

public function errorCB(error:Error, brokenFunction:Function):void
{
trace(error.message);
}

public function sessionInitCB():void {
var tmpId:String = mySession.getSessionId().toString(10);
tmpId = tmpId.substr(tmpId.length - 5);
myNick = "Flex-Native" + tmpId;
factory = new nServiceFactory(mySession,serviceFactoryCB);
}

public function serviceFactoryCB():void
{
var info:nServiceInfo = factory.findService("echo");
factory.connectToService(info,this,connectServiceCB)
}

public function connectServiceCB(service:nEventService):void
{
myService= service;
var props:nEventProperties = new nEventProperties();
var byteArray:ByteArray = new ByteArray();
byteArray.writeUTF("This is a test");
byteArray.position=0;
myService.write(new nConsumeEvent("",null,byteArray));
}

public function retry(failureCount:int, realmName:String):Boolean {
return false;
}

public function disconnected():void {
}

public function reconnected():void {
}

public function go(event:nConsumeEvent):void {
trace("Event ID: "+event.eventID);


Copyright © 2013-2015 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.