how to prepend ISO8583 message length to an ISO8583 message using j8583 library
<p>I am trying to send an ISO8583 message to a server using j8583. I am setting the header in the config.xml file and setting the fields from the same. Now the server configuration requires that 2byte length(Length in hex sent as bytes) should be sent before the incoming ISO8583 message. So my question is :</p>

<p>1)How to calculate the length of the message i.e  the byte representation of the ISO message and how to calculate the length of the byte representation.</p>

<p>2)How to send the length of the message to the server before the ISO8583 message i.e prepended in front of the header.</p>

<p>Here are some of the code excerpts</p>

<pre><code>Client client = new Client(sock);
    Thread reader = new Thread(client, "j8583-client");
    reader.start();

        IsoMessage req = mfact.newMessage(0x200);
        req.setValue(4, amounts[rng.nextInt(amounts.length)],
                IsoType.AMOUNT, 0);
        req.setValue(12, req.getObjectValue(7), IsoType.TIME, 0);
        req.setValue(13, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(15, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(17, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(37, System.currentTimeMillis() % 1000000,
                IsoType.NUMERIC, 12);
        req.setValue(41, data[rng.nextInt(data.length)], IsoType.ALPHA, 16);
        req.setValue(48, data[rng.nextInt(data.length)], IsoType.LLLVAR, 0);
        pending.put(req.getField(11).toString(), req);
        System.err.println(String.format("Sending request %s", req.getField(11)));
                    System.out.println(req.getIsoHeader());
                    System.out.println(req.debugString());

        req.write(sock.getOutputStream(), 2);
</code></pre>

<p>and below is the config </p>

<pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE j8583-config PUBLIC "-//J8583//DTD CONFIG 1.0//EN"
    "http://j8583.sourceforge.net/j8583.dtd"&gt;
&lt;j8583-config&gt;

&lt;!-- These are the ISO headers to be prepended to the message types specified --&gt;
&lt;header type="0200"&gt;ISO026000073&lt;/header&gt;
&lt;header type="0210"&gt;ISO015000055&lt;/header&gt;
&lt;header type="0400"&gt;ISO015000050&lt;/header&gt;
&lt;header type="0410"&gt;ISO015000055&lt;/header&gt;
&lt;header type="0800"&gt;ISO015000015&lt;/header&gt;
&lt;header type="0810"&gt;ISO015000015&lt;/header&gt;

&lt;!-- The client example uses this to create requests --&gt;
&lt;template type="0200"&gt;
    &lt;field num="3" type="NUMERIC" length="6"&gt;650000&lt;/field&gt;
    &lt;field num="32" type="LLVAR"&gt;456&lt;/field&gt;
    &lt;field num="35" type="LLVAR"&gt;4591700012340000=&lt;/field&gt;
    &lt;field num="43" type="ALPHA" length="40"&gt;SOLABTEST             TEST-3       DF MX&lt;/field&gt;
    &lt;field num="49" type="ALPHA" length="3"&gt;484&lt;/field&gt;
    &lt;field num="60" type="LLLVAR"&gt;B456PRO1+000&lt;/field&gt;
    &lt;field num="61" type="LLLVAR"&gt;        1234P&lt;/field&gt;
    &lt;field num="100" type="LLVAR"&gt;999&lt;/field&gt;
    &lt;field num="102" type="LLVAR"&gt;ABCD&lt;/field&gt;
&lt;/template&gt;
</code></pre>

<p>the below is the string representation of the ISO message (the output) :</p>

<pre><code>    Connecting to server
ISO026000073
Sending request 008386
ISO0260000730200B23A800128A180180000000014000000650000000000002050021112445800838612445802110211021103456174591700012340000=0000008984011234567890      SOLABTEST             TEST-3       DF MX010abcdefghij484012B456PRO1+000013        1234P0399904ABCD
</code></pre>

<p>Also how can I see what raw message is being sent from my terminal to the server?</p>