Universal Messaging 9.9 | Universal Messaging Developer Guide | Web Client APIs | Web Developer's Guide for Adobe Flex | Peer to Peer | Peer to Peer Event-based Client
 
Peer to Peer Event-based Client
Universal Messaging Peer to Peer Event-based Services communicate via events which are published by a Client, and received and responded to by an Event-based Server Service.
The Universal Messaging P2P API is simple to use. There are only a very small number of objects and calls that need to be made in order for you to construct a P2P Service Client, connect to a Realm, and find or list available Services.
Creating an Event-based Service Client
The nServiceFactory object takes a connected nirvana session and a callback for when the service is connected:

private var factory:nServiceFactory

private function createP2P():void{
factory = new nServiceFactory( mySession, serviceFactoryCB );
}
When the nServiceFactory calls the callback then we can use factory to findServices and then connect to a Service. findServices takes a name of a service and connectToService takes the nServiceInfo, a nEventListener and a connected callback. The following snippets shows how this would be done:

private function serviceFactoryCB():void{
var info:nServiceInfo = factory.findService("example");
factory.connectToService(info,this,connectServiceCB);
}
Once the Client has connected to an instance of a Server Service, the developer's custom business logic can then be applied.
Sending Events to Server Services
Once you have connected to the Service, and you have an instance of the Service, you can then begin publishing your Universal Messaging events to the Service, by using the following command:

serv.write(new nConsumeEvent("TAG",null, byteArray));
The Client Service can receive events from the Server Service asynchronously via a callback interface.
Asynchronously Receiving Events from the Server Service
A Client MUST asynchronously receive events from the Event-based Server Service by implementing the nEventServiceListener interface and its go method:

public void go( event:nConsumeEvent) {
trace("Event ID: "+event.eventID);
}
Examples
The following full example source code shows how to implement an Event-based Client:
*An Event-based Peer to Peer Client
For more information on Universal Messaging Peer to Peer Services please see the API documentation.

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.
Innovation Release