Universal Messaging Developer Guide : Enterprise APIs : Enterprise Developer's Guide for Java : Peer to Peer Services : Peer to Peer Stream-based Clients
Peer to Peer Stream-based Clients
Universal Messaging Peer to Peer Stream-based Services communicate via input and output streams on both the Stream-based Client and the Stream-based Server Service.
Anything written to the output stream of the Stream-based Service Client is received via the input stream of the Stream-based Server Service and vice versa.
Creating a Stream-based Client
The nServiceFactory object establishes a connection with the Universal Messaging Realm, and is the factory object from which we can find our Service, or obtain a list of available Services:

String[] RNAME={"nsp://127.0.0.1:9000"};
nSessionAttributes nsa = new nSessionAttributes(RNAME);
nServiceFactory factory = new nServiceFactory( nsa );

nServiceInfo info = factory.findService("example");
nEventService serv = (nEventService)factory.connectToService( info );
Once the Client has connected to an instance of a Server Service, the developer's custom business logic can then be applied.
Writing Client Data to a Stream-based Server Service
Once a client has connected to a Service, the client can write data to the Service. The client can obtain a reference to the Service's Output Stream object and then write to it as follows:

OutputStream oStream = serv.getOutputStream();
oStream.write((new UTF8Encoding()).GetBytes("Hello World"));
oStream.flush();
Receiving Responses from a Stream-based Server Service
To receive responses from the Service, the client must first obtain a reference to the Service's Input Stream object, and then read from it as follows:

InputStream iStream = serv.getInputStream();
byte[] buff = new byte[ 100 ];
try {
InputStream is = serv.getInputStream();
while ( true ) {
is.read( buff );
System.out.println("Read "+new String(buff));
}
} catch ( Exception ex ) {
}
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback