Send And Receive The Data From One JPOS Server To Another JPOS

69 views
Skip to first unread message

Karimullah Syed

unread,
Apr 12, 2017, 7:51:43 AM4/12/17
to jPOS Users
Hi JPOS USERS,

I'm writing the JPOSTestClient to Send and Receive the Data From one JPOS Server To Another JPOS Server May be it use full.


public class JposClient {
public static void main(String[] args) throws IOException, ISOException {
byte[] tpduHeader = new byte[10];
tpduHeader = ISOUtil.str2bcd("6000000000",true);
ISO87BINNOPackager packager = new ISO87BINNOPackager();
BaseChannel channel = new NACChannel(packager, tpduHeader);
channel.setHost("192.168.1.177", 1980);
channel.connect();
System.out.println("Method: Inside process()" + "- channelConnected : " + channel.isConnected());
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.setMTI("0200");
isoMsg.set(2, "011414533");
isoMsg.set(3, "000081");
isoMsg.set(11, "000002");
isoMsg.set(12, "114145");
isoMsg.set(13, "1229");
isoMsg.set(24, "999");
isoMsg.set(26, "05");
isoMsg.set(34, "0020879913");
isoMsg.set(41, "90000019");
isoMsg.set(63, "UNICDB803 - 2.1.0");
 byte msgbytes [] = isoMsg.pack();
          byte b [] = new byte[2];
          b[0] =0x00;
          b[1] = (byte) (isoMsg.pack().length + tpduHeader.length);
          byte [] header = addTwobyteArray(b, tpduHeader);
          byte [] data = addTwobyteArray(header, msgbytes);
          channel.getSocket().getOutputStream().write(data, 0, data.length);
ISOMsg responseIsoMsg = new ISOMsg();
responseIsoMsg.setPackager(packager);
responseIsoMsg = channel.receive();
System.out.println(responseIsoMsg);
channel.getSocket().close();
channel.disconnect();
}
public static byte[] addTwobyteArray(byte []array1,byte []array2) {
        byte[] result = new byte[array1.length + array2.length];
        for (int i = 0; i < array1.length; i++) {
            result[i] = array1[i];
        }
        for (int i = array1.length; i < result.length; i++) {
            result[i] = array2[i - array1.length];
        }
        return result;

    }
}


Thanks,
Karimullah Syed.

Alejandro Revilla

unread,
Apr 12, 2017, 11:51:48 AM4/12/17
to jPOS Users
Thank you for sharing, but your code actually doesn't include jPOS best practices. I suggest you take a look at the client simulator and server simulator code in jPOS-EE (http://jpos.org/doc/jPOS-EE.pdf) for a better example using Q2, and a multiplexer (QMUX).



Reply all
Reply to author
Forward
0 new messages