== TCP/IP Socket-based channels

Most TCP/IP-based channel implementations extend  
+org.jpos.iso.BaseChannel+ and just override the 
+sendMessageLength+ and +getMessageLength+ methods. 

Let's have a look at +org.jpos.iso.channel.CSChannel+: 
it uses a two-byte message length header sent in network 
byte order (nbo) plus two bytes reserved for future use: 

[source,java]
----
public class CSChannel extends BaseChannel {
    ...
    ...
    protected void sendMessageLength(int len) throws IOException {
        serverOut.write (len >> 8);
        serverOut.write (len);
        serverOut.write (0);
        serverOut.write (0);
    }
    ...
    ...
    protected int getMessageLength() throws IOException, ISOException {
        int l = 0;
        byte[] b = new byte[4];
        while (l == 0) {
            serverIn.readFully(b,0,4);
            l = ((((int)b[0])&0xFF) << 8) | (((int)b[1])&0xFF);
            if (l == 0) {
                serverOut.write(b);
                serverOut.flush();
            }
        }
        return l;
    }
}
----

Here is a partial list of current channel implementations 
(for a complete list, have a look at +jpos/src/main/java/org/jpos/iso/channel+): 

[cols="2,6", options="header"]
|===============
|Class name|Wire protocol
|CSChannel|
LL LL 00 00 [header] ISO-DATA 
LL LL represents the [header+] ISO-DATA length in network byte order 
00 00 reserved for future use 
The header is optional 
ISO-DATA: ISO-8583 image 

|NACChannel|
LL LL [TPDU] ISO-DATA 
LL LL represents the TPDU+ISO-DATA length  in network byte order 
Optional TPDU (transport protocol data unit) 
ISO-DATA: ISO-8583 image 

|NCCChannel|
LL LL [TPDU] ISO-DATA 
LL LL represents the TPDU+ISO-DATA length  in BCD (binary coded decimal) 
Optional TPDU (transport protocol data unit) 
ISO-DATA: ISO-8583 image 

|ASCIIChannel|LLLL [header] ISO-DATA
      LLLL four bytes ASCII [header+] ISO-DATA length
Optional header 
ISO-DATA: ISO-8583 image 

|RawChannel|
LL LL LL LL [header]  ISO-DATA
LL LL LL LL is [header+] ISO-DATA length  in network byte order

ISO-DATA: ISO-8583 image

|VAPChannel|
LL LL 00 00 header ISO-DATA 
LL LL represents the header+ISO-DATA length  in network byte order 
00 00 reserved for future use 
VAP-specific header 
ISO-DATA: ISO-8583 image 

|PADChannel|
[header] ISO-DATA 
Stream-based channel reads messages on-the-fly without using any kind of message boundary indicator.

|X25Channel
|X25 is similar to PADChannel but uses a slightly different
 strategy. Instead of pulling an ISO-8583 from a stream, unpacking
it on the fly, X25Channel attempts to read full TCP/IP packets
by specifying a small timeout value. Whenever possible, PADChannel
seems like a better solution; however, certain X.25 packet 
assembler/disassemblers sometimes send garbage over the wire
(i.e. ETXs) which might confuse PADChannel.

|XMLChannel|
Send/Receive messages in jPOS's internal XML message representation
     
|LogChannel|
Similar to XMLChannel, but you can feed it a jPOS Log, 
which is suitable to replay sessions

|===============

