Discussion:
Java/CPI-C Sample Client/Server Test Programs for use with IBM Communications Server
(too old to reply)
f***@gmail.com
2007-04-18 02:02:48 UTC
Permalink
For anyone having to battle with Java/CPIC/IBM communications server
here is a sample I created using the loopback adapter created in
http://groups.google.com.au/group/ibm.software.commserver.aix/browse_thread/thread/2a6114371c13c753/30e5fa70533126a0?lnk=gst&q=sam+redfern&rnum=1&hl=en#30e5fa70533126a0

It seems to be impossible to get hold of JPingD, the server portion of
the JPing test program provided with comm server. Together with the
fact that you need super powers to find some of the documentation the
process of creating such a basic application was made very annoying,
not difficult, just annoying. But this group was of great help.

So this is for anyone else who wants to have some fun with Java, CPI-C
and CommServer. This is by no means perfect, but it shows the basic
communication flow and associated java methods. I have included alot
of output statements, which were really for myself and came in handy
when debuging.

Debugging is another fun issue. I recommend looking at logging and
tracing for Comm Server on AIX in the documentation. It would take
another few paragraph to explain it all :P Documentation is not always
easy to come by, but http://www-306.ibm.com/software/network/commserver/library/
was helpful amd I had a few other pdfs emailed to me.

Running the code (I was using java 1.4). Compile. Then to execute the
send program I used 'java -Djava.library.path=/usr/lib/sna
CPICSendTest.class' and 'java -Djava.library.path=/usr/lib/sna
CPICrecvTest.class'. There are a number of ways to set the library
path, this worked for me.

Now there are two options for running the partner TP, you can get comm
server to kick off the application (i.e. partner TP) or you can have
an application that sits and waits for connections to be made and then
handles them.

In the first case, you have to define a transaction program in comm
server, which can be done from the same menu u define side information
from. This was not mentioned in the post i referenced at the start. in
this definition u tell comm server which external program to run, it
could be a java program or otherwise. In this case the partner TP does
not run until the local TP executes the allocate command at which
point comm server then starts up the partner TP (using the TP
configuration) and the TPs begin to send and receive data.

If u are running a server, you might want to have the parner TP always
running and simply accept conversations whenever the local TP wants to
start a conversation, in the same way a TCP/IP listener socket works.
In this case, u simple replace the call to accept (cmaccp) in
CPICRecvTest with the code I put below it. For further description of
the calls i use in this extra code see the document "Communications
Server for AIX" at http://www-306.ibm.com/software/network/commserver/library/.
In this case, you would run CPICRecvTest first, it will sit and wait
for a conversation to be started bt the local TP. Running CPICSendTest
will then begin communication.

I hope I have covered the most important stuff, at the end of the day
it takes trial and error to get it working for you.

Keywords: APPC Java CPIC CPI-C JPing JPingD APing IBM Communications
Server

Good Luck.
FD

CPICSendTest.java--------------------------------------------------------------------------------------------------------------------------------------
import java.util.Calendar;
import COM.ibm.eNetwork.cpic.*;

public class CPICSendTest {

String[] conversation;
byte[] conversationId;
CPIC cpicObject;
CPICReturnCode cpic_return_code;
int maxBufferSize;
CPICControlInformationReceived cpicReturnReceived;

public static void main(String[] args) {
new CPICSendTest();
}

public CPICSendTest() {
cpicObject = new CPIC();
conversationId = new byte[cpicObject.CM_CID_SIZE];
cpic_return_code = new CPICReturnCode(0);
cpicReturnReceived = new CPICControlInformationReceived(0);

conversation = new String[3];
conversation[0] = "Hello";
conversation[1] = "How are you?";
conversation[2] = "What your name?";
talk();
}

public void talk() {
String sSymbolicDestination = "LOOP ";

cpicObject.cminit(conversationId, sSymbolicDestination,
cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Error initialising conversation:" +
cpic_return_code.intValue());

this.setMaxBufferSize();

cpicObject.cmallc(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Error allocating:" +
cpic_return_code.intValue());

this.printConversationState();
this.sendData();
this.printConversationState();
this.receiveData();
this.printConversationState();

cpicObject.cmdeal(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Deallocate. " + cpic_return_code.intValue());
}

private void sendData() {
byte[] sndBuffer = new byte[maxBufferSize];
CPICLength cpicSendLength;

System.out.println("***START SENDING*** " + this.getTime());
for (int i = 0; i < conversation.length; i++) {
System.out.println("i:" + i);
byte[] sendBytes = conversation[i].getBytes();
for (int j = 0; j < sendBytes.length; j++) {
sndBuffer[j] = sendBytes[j];
}
cpicSendLength = new CPICLength(conversation[i].length());

cpicObject.cmsend(conversationId, sndBuffer, cpicSendLength,
cpicReturnReceived, cpic_return_code);

if (cpic_return_code.intValue() != CPICReturnCode.CM_OK) {
System.out.println("Error sending:" +
cpic_return_code.intValue());
} else {
System.out.println("\tSent:" + conversation[i]);
}
System.out.println("\tError Code:" + cpic_return_code.intValue());
System.out.println("\tReturnReceived:" +
cpicReturnReceived.intValue());
}
System.out.println("***FINISH SENDING*** " + this.getTime());
}

private void receiveData() {
CPICDataReceivedType data_received = new CPICDataReceivedType(0);
CPICLength received_length = new CPICLength(0);
CPICStatusReceived status_received = new CPICStatusReceived(0);
byte[] rcvBuffer = new byte[maxBufferSize];
CPICLength requested_length = new CPICLength(maxBufferSize);

System.out.println("***START RECEIVING*** " + this.getTime());
for (int i = 0; i < conversation.length; i++) {
System.out.println("i:" + i);
cpicObject.cmrcv(conversationId, rcvBuffer, requested_length,
data_received,
received_length, status_received, cpicReturnReceived,
cpic_return_code);
System.out.println("\tError code:" + cpic_return_code.intValue());
System.out.println("\tRts received:" +
cpicReturnReceived.intValue());
System.out.println("\tStatus received:" +
status_received.intValue());

if ((cpic_return_code.intValue() == CPICReturnCode.CM_OK)
|| (cpic_return_code.intValue() ==
CPICReturnCode.CM_DEALLOCATED_NORMAL)) {
String str = new String(rcvBuffer);
System.out.println("\tReceived:" + str);
} else {
System.out.println("\tData not received.Error code:" +
cpic_return_code.intValue());
}
}
System.out.println("***FINISH RECEIVING*** " + this.getTime());
}

private void setMaxBufferSize() {
CPICLength mbs = null;
try {
mbs = new CPICLength();
cpicObject.cmembs(mbs, cpic_return_code);
cpic_return_code.isOK();
//System.out.println("Max Buffer (cmembs) = " + mbs.intValue());
maxBufferSize = mbs.intValue();
} catch (CPICReturnCode c) {
System.out.println("Extract_Maximum_Buffer_Size error.");
maxBufferSize = -1;
}
}

public void printConversationState() {
// Get conversation state
CPICConversationState conversation_state = new
CPICConversationState();
cpicObject.cmecs(conversationId, conversation_state,
cpic_return_code);
System.out.println("Conversation state:"
+ conversation_state.intValue());
}

private String getTime() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.HOUR_OF_DAY) + ":" +
cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
}
}

CPICRecvTest.java--------------------------------------------------------------------------------------------------------------------------------------
import COM.ibm.eNetwork.cpic.*;
import java.util.Calendar;

public class CPICRecvTest {

String[] conversation;
int maxBufferSize;
CPIC cpicObject;
CPICReturnCode cpic_return_code;
byte[] conversationId;
CPICControlInformationReceived cpicReturnReceived;

public static void main(String[] args) {
new CPICRecvTest();
}

public CPICRecvTest() {
cpicObject = new CPIC();
cpic_return_code = new CPICReturnCode(0);
conversationId = new byte[CPIC.CM_CID_SIZE];
cpicReturnReceived = new CPICControlInformationReceived(0);

conversation = new String[3];
conversation[0] = "Hi";
conversation[1] = "Im good?";
conversation[2] = "My name is fred?";
talk();
}

public void talk() {

// Accept conversation
cpicObject.cmaccp(conversationId, cpic_return_code);

if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Conversation not accepted. Return Code:" +
cpic_return_code.intValue());

System.out.println("Conversation accepted, receiving data...");

setMaxBufferSize();
this.printConversationState();
this.receiveData();
this.printConversationState();
this.sendData();

// Deallocate
cpicObject.cmdeal(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Deallocate. " + cpic_return_code.intValue());
}

private void receiveData() {
CPICLength requested_length = new CPICLength(9975);
CPICDataReceivedType data_received = new CPICDataReceivedType(0);
CPICLength received_length = new CPICLength(0);
CPICStatusReceived status_received = new CPICStatusReceived(0);
byte[] rcvBuffer = new byte[maxBufferSize];

while(status_received.intValue() !=
CPICStatusReceived.CM_SEND_RECEIVED) {
// Receive data
cpicObject.cmrcv(conversationId, rcvBuffer, requested_length,
data_received,
received_length, status_received, cpicReturnReceived,
cpic_return_code);

// Some debug statements
//System.out.println("Data Received:" + data_received.intValue());
//System.out.println("Received length:" +
received_length.intValue());
//System.out.println("Status received:" +
status_received.intValue());
//System.out.println("Rts received:" +
cpicReturnReceived.intValue());

if ((cpic_return_code.intValue() == CPICReturnCode.CM_OK)
|| (cpic_return_code.intValue() ==
CPICReturnCode.CM_DEALLOCATED_NORMAL)) {
String str = new String(rcvBuffer);
System.out.println("Received:" + str);
} else {
System.out.println("\tData not received.Error code:" +
cpic_return_code.intValue());
}
}
}

private void sendData() {
byte[] sndBuffer = new byte[maxBufferSize];
CPICLength cpicSendLength;

for (int i = 0; i < conversation.length; i++) {
byte[] sendBytes = conversation[i].getBytes();
for (int j = 0; j < sendBytes.length; j++) {
sndBuffer[j] = sendBytes[j];
}

cpicSendLength = new CPICLength(conversation[i].length());
cpicObject.cmsend(conversationId, sndBuffer, cpicSendLength,
cpicReturnReceived, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK) {
System.out.println("Error sending:" +
cpic_return_code.intValue());
} else {
System.out.println("Sent:" + conversation[i]);
}
System.out.println("Rts received:" +
cpicReturnReceived.intValue());
}
}

public void printTPName() {
byte[] tpName = new byte[CPIC.CM_TPN_SIZE];
CPICLength tpNameLen = new CPICLength();
cpicObject.cmetpn(conversationId, tpName, tpNameLen,
cpic_return_code);
String s = new String(tpName);
System.out.println("TPName:" + s);
}

public void printConversationState() {
// Get conversation state again
CPICConversationState conversation_state = new
CPICConversationState();
cpicObject.cmecs(conversationId, conversation_state,
cpic_return_code);
System.out.println("Conversation state:"
+ conversation_state.intValue());
}

private void setMaxBufferSize() {
CPICLength mbs = null;
try {
mbs = new CPICLength();
cpicObject.cmembs(mbs, cpic_return_code);
cpic_return_code.isOK();
//System.out.println("Max Buffer (cmembs) = " + mbs.intValue());
maxBufferSize = mbs.intValue();
} catch (CPICReturnCode c) {
System.out.println("Extract_Maximum_Buffer_Size error.");
maxBufferSize = -1;
}
}

private String getTime() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.HOUR_OF_DAY) + ":" +
cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------

Code to replace the call to cmaccp in CPICRecvTest if you want the
partner TP to act like a TCP/IP listener.

Replace:
// Accept conversation
cpicObject.cmaccp(conversationId, cpic_return_code);

With the following:

/*
* User started program, as opposed to being invoked when CPICSendTest
initiates a conversation.
* i.e. CPICRecvTest2 waits for an incoming connection from
CPICSendTest
*/

byte[] localTPName = "SRVR".getBytes(); // Does not have to be
exactly 8 characters in length like side info
CPICLength localTPNameLen = new CPICLength(localTPName.length);
cpicObject.cmsltp(localTPName, localTPNameLen, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Conversation not initialised. Return Code:" +
cpic_return_code.intValue());

// Initialise incoming
cpicObject.cminic(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Conversation not initialised. Return Code:" +
cpic_return_code.intValue());

System.out.println("Accepting incoming conversations...");

// Accept incoming conversation
//cpicObject.cmaccp(conversationId, cpic_return_code);
cpicObject.cmacci(conversationId, cpic_return_code);
l***@us.ibm.com
2007-04-19 10:59:13 UTC
Permalink
Newsgroups: ibm.software.commserver.aix
Subject: Java/CPI-C Sample Client/Server Test Programs for use with
IBM Communications Server
Date: 17 Apr 2007 19:02:48 -0700
Organization: http://groups.google.com
For anyone having to battle with Java/CPIC/IBM communications server
here is a sample I created using the loopback adapter created in
http://groups.google.com.au/group/ibm.software.commserver.aix/browse_thread/thread/2a6114371c13c753/30e5fa70533126a0?lnk=gst&q=sam+redfern&rnum=1#30e5fa70533126a0
It seems to be impossible to get hold of JPingD, the server portion of
the JPing test program provided with comm server. Together with the
fact that you need super powers to find some of the documentation the
process of creating such a basic application was made very annoying,
not difficult, just annoying. But this group was of great help.
So this is for anyone else who wants to have some fun with Java, CPI-C
and CommServer. This is by no means perfect, but it shows the basic
communication flow and associated java methods. I have included alot
of output statements, which were really for myself and came in handy
when debuging.
Debugging is another fun issue. I recommend looking at logging and
tracing for Comm Server on AIX in the documentation. It would take
another few paragraph to explain it all :P Documentation is not always
easy to come by, but
http://www-306.ibm.com/software/network/commserver/library/
was helpful amd I had a few other pdfs emailed to me.
Running the code (I was using java 1.4). Compile. Then to execute the
send program I used 'java -Djava.library.path=/usr/lib/sna
CPICSendTest.class' and 'java -Djava.library.path=/usr/lib/sna
CPICrecvTest.class'. There are a number of ways to set the library
path, this worked for me.
Now there are two options for running the partner TP, you can get comm
server to kick off the application (i.e. partner TP) or you can have
an application that sits and waits for connections to be made and then
handles them.
In the first case, you have to define a transaction program in comm
server, which can be done from the same menu u define side information
from. This was not mentioned in the post i referenced at the start. in
this definition u tell comm server which external program to run, it
could be a java program or otherwise. In this case the partner TP does
not run until the local TP executes the allocate command at which
point comm server then starts up the partner TP (using the TP
configuration) and the TPs begin to send and receive data.
If u are running a server, you might want to have the parner TP always
running and simply accept conversations whenever the local TP wants to
start a conversation, in the same way a TCP/IP listener socket works.
In this case, u simple replace the call to accept (cmaccp) in
CPICRecvTest with the code I put below it. For further description of
the calls i use in this extra code see the document "Communications
Server for AIX" at
http://www-306.ibm.com/software/network/commserver/library/.
In this case, you would run CPICRecvTest first, it will sit and wait
for a conversation to be started bt the local TP. Running CPICSendTest
will then begin communication.
I hope I have covered the most important stuff, at the end of the day
it takes trial and error to get it working for you.
Keywords: APPC Java CPIC CPI-C JPing JPingD APing IBM Communications
Server
Good Luck.
FD
CPICSendTest.java--------------------------------------------------------------------------------------------------------------------------------------
import java.util.Calendar;
import COM.ibm.eNetwork.cpic.*;

public class CPICSendTest {

String[] conversation;
byte[] conversationId;
CPIC cpicObject;
CPICReturnCode cpic_return_code;
int maxBufferSize;
CPICControlInformationReceived cpicReturnReceived;

public static void main(String[] args) {
new CPICSendTest();
}

public CPICSendTest() {
cpicObject = new CPIC();
conversationId = new byte[cpicObject.CM_CID_SIZE];
cpic_return_code = new CPICReturnCode(0);
cpicReturnReceived = new CPICControlInformationReceived(0);

conversation = new String[3];
conversation[0] = "Hello";
conversation[1] = "How are you?";
conversation[2] = "What your name?";
talk();
}

public void talk() {
String sSymbolicDestination = "LOOP ";

cpicObject.cminit(conversationId, sSymbolicDestination,
cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Error initialising conversation:" +
cpic_return_code.intValue());

this.setMaxBufferSize();

cpicObject.cmallc(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Error allocating:" +
cpic_return_code.intValue());

this.printConversationState();
this.sendData();
this.printConversationState();
this.receiveData();
this.printConversationState();

cpicObject.cmdeal(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Deallocate. " + cpic_return_code.intValue());
}

private void sendData() {
byte[] sndBuffer = new byte[maxBufferSize];
CPICLength cpicSendLength;

System.out.println("***START SENDING*** " + this.getTime());
for (int i = 0; i < conversation.length; i++) {
System.out.println("i:" + i);
byte[] sendBytes = conversation[i].getBytes();
for (int j = 0; j < sendBytes.length; j++) {
sndBuffer[j] = sendBytes[j];
}
cpicSendLength = new CPICLength(conversation[i].length());

cpicObject.cmsend(conversationId, sndBuffer, cpicSendLength,
cpicReturnReceived, cpic_return_code);

if (cpic_return_code.intValue() != CPICReturnCode.CM_OK) {
System.out.println("Error sending:" +
cpic_return_code.intValue());
} else {
System.out.println("\tSent:" + conversation[i]);
}
System.out.println("\tError Code:" + cpic_return_code.intValue());
System.out.println("\tReturnReceived:" +
cpicReturnReceived.intValue());
}
System.out.println("***FINISH SENDING*** " + this.getTime());
}

private void receiveData() {
CPICDataReceivedType data_received = new CPICDataReceivedType(0);
CPICLength received_length = new CPICLength(0);
CPICStatusReceived status_received = new CPICStatusReceived(0);
byte[] rcvBuffer = new byte[maxBufferSize];
CPICLength requested_length = new CPICLength(maxBufferSize);

System.out.println("***START RECEIVING*** " + this.getTime());
for (int i = 0; i < conversation.length; i++) {
System.out.println("i:" + i);
cpicObject.cmrcv(conversationId, rcvBuffer, requested_length,
data_received,
received_length, status_received, cpicReturnReceived,
cpic_return_code);
System.out.println("\tError code:" + cpic_return_code.intValue());
System.out.println("\tRts received:" +
cpicReturnReceived.intValue());
System.out.println("\tStatus received:" +
status_received.intValue());

if ((cpic_return_code.intValue() == CPICReturnCode.CM_OK)
|| (cpic_return_code.intValue() ==
CPICReturnCode.CM_DEALLOCATED_NORMAL)) {
String str = new String(rcvBuffer);
System.out.println("\tReceived:" + str);
} else {
System.out.println("\tData not received.Error code:" +
cpic_return_code.intValue());
}
}
System.out.println("***FINISH RECEIVING*** " + this.getTime());
}

private void setMaxBufferSize() {
CPICLength mbs = null;
try {
mbs = new CPICLength();
cpicObject.cmembs(mbs, cpic_return_code);
cpic_return_code.isOK();
//System.out.println("Max Buffer (cmembs) = " + mbs.intValue());
maxBufferSize = mbs.intValue();
} catch (CPICReturnCode c) {
System.out.println("Extract_Maximum_Buffer_Size error.");
maxBufferSize = -1;
}
}

public void printConversationState() {
// Get conversation state
CPICConversationState conversation_state = new
CPICConversationState();
cpicObject.cmecs(conversationId, conversation_state,
cpic_return_code);
System.out.println("Conversation state:"
+ conversation_state.intValue());
}

private String getTime() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.HOUR_OF_DAY) + ":" +
cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
}
}

CPICRecvTest.java--------------------------------------------------------------------------------------------------------------------------------------
import COM.ibm.eNetwork.cpic.*;
import java.util.Calendar;

public class CPICRecvTest {

String[] conversation;
int maxBufferSize;
CPIC cpicObject;
CPICReturnCode cpic_return_code;
byte[] conversationId;
CPICControlInformationReceived cpicReturnReceived;

public static void main(String[] args) {
new CPICRecvTest();
}

public CPICRecvTest() {
cpicObject = new CPIC();
cpic_return_code = new CPICReturnCode(0);
conversationId = new byte[CPIC.CM_CID_SIZE];
cpicReturnReceived = new CPICControlInformationReceived(0);

conversation = new String[3];
conversation[0] = "Hi";
conversation[1] = "Im good?";
conversation[2] = "My name is fred?";
talk();
}

public void talk() {

// Accept conversation
cpicObject.cmaccp(conversationId, cpic_return_code);

if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Conversation not accepted. Return Code:" +
cpic_return_code.intValue());

System.out.println("Conversation accepted, receiving data...");

setMaxBufferSize();
this.printConversationState();
this.receiveData();
this.printConversationState();
this.sendData();

// Deallocate
cpicObject.cmdeal(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Deallocate. " + cpic_return_code.intValue());
}

private void receiveData() {
CPICLength requested_length = new CPICLength(9975);
CPICDataReceivedType data_received = new CPICDataReceivedType(0);
CPICLength received_length = new CPICLength(0);
CPICStatusReceived status_received = new CPICStatusReceived(0);
byte[] rcvBuffer = new byte[maxBufferSize];

while(status_received.intValue() !=
CPICStatusReceived.CM_SEND_RECEIVED) {
// Receive data
cpicObject.cmrcv(conversationId, rcvBuffer, requested_length,
data_received,
received_length, status_received, cpicReturnReceived,
cpic_return_code);

// Some debug statements
//System.out.println("Data Received:" + data_received.intValue());
//System.out.println("Received length:" +
received_length.intValue());
//System.out.println("Status received:" +
status_received.intValue());
//System.out.println("Rts received:" +
cpicReturnReceived.intValue());

if ((cpic_return_code.intValue() == CPICReturnCode.CM_OK)
|| (cpic_return_code.intValue() ==
CPICReturnCode.CM_DEALLOCATED_NORMAL)) {
String str = new String(rcvBuffer);
System.out.println("Received:" + str);
} else {
System.out.println("\tData not received.Error code:" +
cpic_return_code.intValue());
}
}
}

private void sendData() {
byte[] sndBuffer = new byte[maxBufferSize];
CPICLength cpicSendLength;

for (int i = 0; i < conversation.length; i++) {
byte[] sendBytes = conversation[i].getBytes();
for (int j = 0; j < sendBytes.length; j++) {
sndBuffer[j] = sendBytes[j];
}

cpicSendLength = new CPICLength(conversation[i].length());
cpicObject.cmsend(conversationId, sndBuffer, cpicSendLength,
cpicReturnReceived, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK) {
System.out.println("Error sending:" +
cpic_return_code.intValue());
} else {
System.out.println("Sent:" + conversation[i]);
}
System.out.println("Rts received:" +
cpicReturnReceived.intValue());
}
}

public void printTPName() {
byte[] tpName = new byte[CPIC.CM_TPN_SIZE];
CPICLength tpNameLen = new CPICLength();
cpicObject.cmetpn(conversationId, tpName, tpNameLen,
cpic_return_code);
String s = new String(tpName);
System.out.println("TPName:" + s);
}

public void printConversationState() {
// Get conversation state again
CPICConversationState conversation_state = new
CPICConversationState();
cpicObject.cmecs(conversationId, conversation_state,
cpic_return_code);
System.out.println("Conversation state:"
+ conversation_state.intValue());
}

private void setMaxBufferSize() {
CPICLength mbs = null;
try {
mbs = new CPICLength();
cpicObject.cmembs(mbs, cpic_return_code);
cpic_return_code.isOK();
//System.out.println("Max Buffer (cmembs) = " + mbs.intValue());
maxBufferSize = mbs.intValue();
} catch (CPICReturnCode c) {
System.out.println("Extract_Maximum_Buffer_Size error.");
maxBufferSize = -1;
}
}

private String getTime() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.HOUR_OF_DAY) + ":" +
cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------

Code to replace the call to cmaccp in CPICRecvTest if you want the
partner TP to act like a TCP/IP listener.

Replace:
// Accept conversation
cpicObject.cmaccp(conversationId, cpic_return_code);

With the following:

/*
* User started program, as opposed to being invoked when CPICSendTest
initiates a conversation.
* i.e. CPICRecvTest2 waits for an incoming connection from
CPICSendTest
*/

byte[] localTPName = "SRVR".getBytes(); // Does not have to be
exactly 8 characters in length like side info
CPICLength localTPNameLen = new CPICLength(localTPName.length);
cpicObject.cmsltp(localTPName, localTPNameLen, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Conversation not initialised. Return Code:" +
cpic_return_code.intValue());

// Initialise incoming
cpicObject.cminic(conversationId, cpic_return_code);
if (cpic_return_code.intValue() != CPICReturnCode.CM_OK)
System.out.println("Conversation not initialised. Return Code:" +
cpic_return_code.intValue());

System.out.println("Accepting incoming conversations...");

// Accept incoming conversation
//cpicObject.cmaccp(conversationId, cpic_return_code);
cpicObject.cmacci(conversationId, cpic_return_code);




The original post above is at:
http://groups.google.com/group/ibm.software.commserver.aix/msg/270d5d8d29e13db2
in case the wrapping of this reply makes it unreadable.

Nice examples. One comment, you show a consistent use of
... cpic_return_code.intValue() != CPICReturnCode.CM_OK ...
after every cpic call, which is good, but when you get a
CPICReturnCode which is not CM_OK you don't always end the
transaction program cleanly. In other words there should
probably be an error path which always does a cmdeal()
to close the conversation and end the TP. There is one
cmdeal after a failed cmallc/cmaccp, but the conversation
could also fail in other places.

Paul Landay

Loading...