Sending custom message using channel

111 views
Skip to first unread message

rahul singh

unread,
Jun 23, 2015, 3:05:37 AM6/23/15
to jpos-...@googlegroups.com
My message format is given below:

02 +2 bytes BCD(body length) + body + 03 +LRC

For example

02012760008000000200 7038040000CB10111686 21380000000024290000 00000000010000107816 
28451504150210303137 31303036373838303530 30303030303030313731 05303030303500063030 
30303032000630303031 3037AFC5A3C312A0BAD4 00203030303030303030 30303030303030303030 
30309334B2D4B0DAFFB5 03FF

Can anybody please help me how to send this message?

Initial attempt I have made, i have overridden following 2 methods 

protected void sendMessageLength(int len) throws IOException {
serverOut.write (2); //TO SEND 02 mentioned at start of message.
        serverOut.write (len >> 8);
        serverOut.write (len);
    }

    protected void sendMessageTrailler(ISOMsg m, int len) throws IOException
    {
serverOut.write (3);
serverOut.write (255); // TO SEND 03 FF at the end of message

    }

However, these seems not working. Any suggestion will be highly appreciated.


Thanks,
Manoj

chhil

unread,
Jun 23, 2015, 3:15:50 AM6/23/15
to jpos-...@googlegroups.com
I suggest you search the group for messages supporting STX (start of text character 0x02) ETX (end of text 0x03) and LRC.

You need to calculate LRC and not hard code it to FF.

-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/02f6bccf-d8cf-4591-a5d9-7e6fe82cd692%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rahul singh

unread,
Jun 23, 2015, 3:38:27 AM6/23/15
to jpos-...@googlegroups.com
Thanks Chill, I tried searching it but could not found some concrete solution/suggestion around it. Can you please help me with some reference if you have something handy.

Thanks,

Victor Salaman

unread,
Jun 23, 2015, 3:41:25 AM6/23/15
to jpos-...@googlegroups.com

You need to read your spec… Sending the message might be easy, receiving it might be another story altogether. Your protocol might depend that upon receiving a data frame, you calculate the incoming lrc and acknowledge (ACK) or reject (NAK) the message, where the sending device might retry for a couple of times and if the decoding fails (maybe because of a bad line!), it will end the transmission (EOT) and hangup! So you need to tune in to your protocol spec, and figure out if you’ll need to respond with ACK,NAK and manage enqueues (ENQ) and “end transmissions” (EOT).

If it’s just simple framing (STX/ETX at send), you can override sendMessageLength/sendMessageTrailler. BTW, you’re overriding the wrong method.. you want to override the method with signature:

protected void sendMessageTrailler(ISOMsg m, byte[] b) throws IOException

so you can calculate the lrc from the packed message in “b”.

/V


--

chhil

unread,
Jun 23, 2015, 3:44:16 AM6/23/15
to jpos-...@googlegroups.com
 "these seems not working"
What is specifically not working for you?
Can you show us a hexdump of the message you have by dumping it from your channel code?
Do you have an ISO bitmapped message or a fsd message (fields separated by delimiters)?

-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

rahul singh

unread,
Jun 23, 2015, 5:00:06 AM6/23/15
to jpos-...@googlegroups.com
Here is my message dump:

00000000  02 01 01 60 00 00 00 80  02 00 70 38 04 00 00 CB   ...`.... ..p8.... 
00000010  10 11 16 86 21 39 00 00  00 00 15 29 00 00 00 00   ....!9.. ...).... 
00000020  00 00 10 00 00 23 52 15  06 23 15 06 23 02 10 37   .....#R. .#..#..7 
00000030  36 34 37 38 35 36 38 30  30 30 30 30 30 30 30 30   64785680 00000000 
00000040  30 31 20 20 20 20 30 31  35 30 30 31 36 30 30 31   01    01 50016001 
00000050  36 33 31 33 32 33 33 33  31 33 32 33 33 00 01 00   63132333 13233... 
00000060  44 34 44 31 42 36 32 36  03 FF                              D4D1B626 ..

I have overridden 3 methods as below:

    protected void sendMessageLength(int len) throws IOException {
serverOut.write (ISOUtil.STX);
super.sendMessageLength(len);
    }

    protected void sendMessageTrailler(ISOMsg m, byte[] b) throws IOException{
serverOut.write (ISOUtil.ETX);
serverOut.write (255);
    }
    protected int getMessageLength() throws IOException, ISOException {
        return 1;
    }

I am getting below exception,  and assuming proper message is not being sent and thats why server is not returning response.

<log realm="org.jpos.q2.iso.ChannelAdaptor" at="Tue Jun 23 14:28:01 IST 2015.527">
  <warn>
    channel-receiver-xinsheng-receive
    <exception name="Connection reset">
    java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:196)
        at java.net.SocketInputStream.read(SocketInputStream.java:122)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
        at java.io.DataInputStream.readFully(DataInputStream.java:195)
        at org.jpos.iso.BaseChannel.readHeader(BaseChannel.java:621)
        at org.jpos.iso.BaseChannel.receive(BaseChannel.java:655)
        at org.jpos.q2.iso.ChannelAdaptor$Receiver.run(ChannelAdaptor.java:295)
        at java.lang.Thread.run(Thread.java:745)
    </exception>
  </warn>
</log>

Please suggest.


On Tuesday, June 23, 2015 at 12:35:37 PM UTC+5:30, rahul singh wrote:

chhil

unread,
Jun 23, 2015, 5:14:56 AM6/23/15
to jpos-...@googlegroups.com
Why is your getMessageLength hardcoded to 1? You need to add appropriate handling of stripping of STX,ETX and LRC on receiving the message, are you doing that?
You need to make sure you return the appropriate getMessagelength so that it knows how many bytes to read in (you will need to make sure the STC and LRC are accommodated in the length).

Have you tried calculating the lrc and sending it instead of hardcoding it to FF?
Can you just send the example message you provided in your initial post and see if your remote entity likes it and does not disconnect?
Have you asked the remote entity why its disconnecting and telling you whats wrong with the message you are sending?

-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

Victor Salaman

unread,
Jun 23, 2015, 6:52:17 AM6/23/15
to jpos-...@googlegroups.com

On Tue, Jun 23, 2015 at 3:05 AM, rahul singh <m.mano...@gmail.com> wrote:
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

Victor Salaman

unread,
Jun 23, 2015, 7:12:10 AM6/23/15
to jpos-...@googlegroups.com
Sir,

I am not your friend, I am not your enemy. What of all things made you think that I wanted to play "Hangouts" with you? 

Need to talk to someone? Try eHarmony :)

https://www.dropbox.com/s/tosa3qikem58fvn/Screenshot%202015-06-23%2007.10.11.png?dl=0


rahul singh

unread,
Jun 23, 2015, 7:40:09 AM6/23/15
to jpos-...@googlegroups.com
Nothing Victor, Wanted to share my problem/approach with you over messenger and seeking your advice to make this quick. 
Thanks for your advice.

Thanks.


On Tuesday, June 23, 2015 at 12:35:37 PM UTC+5:30, rahul singh wrote:

rahul singh

unread,
Jun 26, 2015, 3:16:26 AM6/26/15
to jpos-...@googlegroups.com
Hi,

I followed Victor's class (https://gist.github.com/vsalaman/b02f9794a7bcc7f7b36d) and found the custom streamReceive() method should be invoked to read the response containing STX and ETX. 

Below is the code from receive method of BaseChannel and flow went into readHeader() everytime, however I think, it should not go into it.

 int len  = getMessageLength();
                int hLen = getHeaderLength();

                if (len == -1 ) {
                    if (hLen > 0) {
                        header = readHeader(hLen);
                    }
                    b = streamReceive();
                }


Please suggest.


On Tuesday, June 23, 2015 at 12:35:37 PM UTC+5:30, rahul singh wrote:

Victor Salaman

unread,
Jun 26, 2015, 3:30:00 AM6/26/15
to jpos-...@googlegroups.com
Hi:

By default there is no header, so it would not try to read one. In other words, if getHeaderLength() returns 0 (like it would if you have not explicitly defined a header), then it will go straight to streamReceive().

/V

June 26, 2015 at 3:16 AM
Hi,

I followed Victor's class (https://gist.github.com/vsalaman/b02f9794a7bcc7f7b36d) and found the custom streamReceive() method should be invoked to read the response containing STX and ETX. 

Below is the code from receive method of BaseChannel and flow went into readHeader() everytime, however I think, it should not go into it.

 int len  = getMessageLength();
                int hLen = getHeaderLength();

                if (len == -1 ) {
                    if (hLen > 0) {
                        header = readHeader(hLen);
                    }
                    b = streamReceive();
                }


Please suggest.


On Tuesday, June 23, 2015 at 12:35:37 PM UTC+5:30, rahul singh wrote:
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
June 23, 2015 at 3:05 AM
My message format is given below:

02 +2 bytes BCD(body length) + body + 03 +LRC

For example

02012760008000000200 7038040000CB10111686 21380000000024290000 00000000010000107816 
28451504150210303137 31303036373838303530 30303030303030313731 05303030303500063030 
30303032000630303031 3037AFC5A3C312A0BAD4 00203030303030303030 30303030303030303030 
30309334B2D4B0DAFFB5 03FF

Can anybody please help me how to send this message?

Initial attempt I have made, i have overridden following 2 methods 

protected void sendMessageLength(int len) throws IOException {
serverOut.write (2); //TO SEND 02 mentioned at start of message.
        serverOut.write (len >> 8);
        serverOut.write (len);
    }

    protected void sendMessageTrailler(ISOMsg m, int len) throws IOException
    {
serverOut.write (3);
serverOut.write (255); // TO SEND 03 FF at the end of message

    }

However, these seems not working. Any suggestion will be highly appreciated.


Thanks,
Manoj

rahul singh

unread,
Jun 26, 2015, 5:28:07 AM6/26/15
to jpos-...@googlegroups.com
Thanks Victor, It helped.

I have not defined any explicit header and it seems working now. However I have message like below:
60 00 00 00 80 02 10 30  20 00 00 02 80 00 19

Initial 5 bytes are TPDU followed by MTI and bimap.

After reading the entire message, jpos started parsing the message including TPDU as well, however I need to exclude the TPDU value (60 00 00 00 80 ) and then parse.

How should I do this, please suggest.

Thanks,


On Tuesday, June 23, 2015 at 12:35:37 PM UTC+5:30, rahul singh wrote:

Victor Salaman

unread,
Jun 26, 2015, 5:35:28 AM6/26/15
to jpos-...@googlegroups.com
Take a look at the NACChannel. Basically you need to merge the NAC TPDU functionality into your channel. You are full of surprises, you had neglected to mention any TPDUs. I wonder what will you come up with tomorrow :)

/V

June 26, 2015 at 5:28 AM
Thanks Victor, It helped.

I have not defined any explicit header and it seems working now. However I have message like below:
60 00 00 00 80 02 10 30  20 00 00 02 80 00 19

Initial 5 bytes are TPDU followed by MTI and bimap.

After reading the entire message, jpos started parsing the message including TPDU as well, however I need to exclude the TPDU value (60 00 00 00 80 ) and then parse.

How should I do this, please suggest.

Thanks,


On Tuesday, June 23, 2015 at 12:35:37 PM UTC+5:30, rahul singh wrote:
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
June 23, 2015 at 3:05 AM
My message format is given below:

02 +2 bytes BCD(body length) + body + 03 +LRC

For example

02012760008000000200 7038040000CB10111686 21380000000024290000 00000000010000107816 
28451504150210303137 31303036373838303530 30303030303030313731 05303030303500063030 
30303032000630303031 3037AFC5A3C312A0BAD4 00203030303030303030 30303030303030303030 
30309334B2D4B0DAFFB5 03FF

Can anybody please help me how to send this message?

Initial attempt I have made, i have overridden following 2 methods 

protected void sendMessageLength(int len) throws IOException {
serverOut.write (2); //TO SEND 02 mentioned at start of message.
        serverOut.write (len >> 8);
        serverOut.write (len);
    }

    protected void sendMessageTrailler(ISOMsg m, int len) throws IOException
    {
serverOut.write (3);
serverOut.write (255); // TO SEND 03 FF at the end of message

    }

However, these seems not working. Any suggestion will be highly appreciated.


Thanks,
Manoj

rahul singh

unread,
Jun 26, 2015, 6:17:04 AM6/26/15
to jpos-...@googlegroups.com
Thanks everyone for advice. I got everything working now.


On Tuesday, June 23, 2015 at 12:35:37 PM UTC+5:30, rahul singh wrote:

Mark Salter

unread,
Jun 27, 2015, 5:20:42 AM6/27/15
to jpos-...@googlegroups.com
On 26/06/15 11:17, rahul singh wrote:
> Thanks everyone for advice. I got everything working now.
How, can you share the solution and perhaps the code for others to
benefit from?

--
Mark
Reply all
Reply to author
Forward
0 new messages