Usually, as shown in the code for A Hello World! Program, you use TipcSvc.getSrv to create a single global RTserver connection. In some cases, you may need to create multiple RTserver connections from your RTclient:
To create multiple RTserver connections, use the TipcSvc.createSrv method. This creates new RTserver connections independent of the global RTserver connection created by TipcSvc.getSrv. TipcSvc.createSrv allows properties to be associated with a TipcSrv object so that each RTserver connection can have its own option settings.
Here is an example of a program that creates multiple RTserver connections:
//-----------------------------------------------------------
// multi.java -- Java application with multiple connections
import com.smartsockets.*; public class multi { public static void main(String[] argv) { TipcMsg msg = null; String text = null; try {// the sender connection
TipcSrv sender = TipcSvc.createSrv(); sender.setOption("ss.unique_subject", "sender");// the receiver connection
TipcSrv receiver = TipcSvc.createSrv(); receiver.setOption("ss.unique_subject", "receiver");// create the message
msg = TipcSvc.createMsg(TipcMt.INFO); msg.setDest("/multi"); msg.appendStr("Hello, World!");// subscribe the receiver connection to subject "/multi"
receiver.setSubjectSubscribe("/multi", true); receiver.flush();// send the message over the sender connection, then close the connection
sender.send(msg); sender.flush(); sender.destroy();// the receiver connection will now receive the message
TipcMsg receivedMsg = receiver.next(TipcDefs.TIMEOUT_FOREVER); receivedMsg.setCurrent(0); text = receivedMsg.nextStr(); } catch (TipcException e) { Tut.fatal(e); }// try-catch
System.out.println("Text from INFO message = " + text); }// main
}// multi
TIBCO SmartSockets™ Java Library User’s Guide and Tutorial Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |