001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.iso.channel; 020 021import java.io.IOException; 022import java.net.ServerSocket; 023 024import org.jpos.iso.BaseChannel; 025import org.jpos.iso.ISOException; 026import org.jpos.iso.ISOMsg; 027import org.jpos.iso.ISOPackager; 028 029/** 030 * four-byte header in nbp 031 */ 032public class GICCChannel extends BaseChannel { 033 /** 034 * Public constructor (used by Class.forName("...").newInstance()) 035 */ 036 public GICCChannel () { 037 super(); 038 } 039 /** 040 * Construct client ISOChannel 041 * @param host server TCP Address 042 * @param port server port number 043 * @param p an ISOPackager 044 * @see ISOPackager 045 */ 046 public GICCChannel (String host, int port, ISOPackager p) { 047 super(host, port, p); 048 } 049 /** 050 * Construct server ISOChannel 051 * @param p an ISOPackager 052 * @exception IOException 053 * @see ISOPackager 054 */ 055 public GICCChannel (ISOPackager p) throws IOException { 056 super(p); 057 } 058 /** 059 * constructs a server ISOChannel associated with a Server Socket 060 * @param p an ISOPackager 061 * @param serverSocket where to accept a connection 062 * @exception IOException 063 * @see ISOPackager 064 */ 065 public GICCChannel (ISOPackager p, ServerSocket serverSocket) 066 throws IOException 067 { 068 super(p, serverSocket); 069 } 070 /** 071 * @param len the packed Message len 072 * @exception IOException 073 */ 074 protected void sendMessageLength(int len) throws IOException { 075 serverOut.write (0); 076 serverOut.write (0); 077 serverOut.write (len >> 8); 078 serverOut.write (len); 079 } 080 /** 081 * @return the Message len 082 * @exception IOException, ISOException 083 */ 084 protected int getMessageLength() throws IOException, ISOException { 085 int l = 0; 086 byte[] b = new byte[4]; 087 while (l == 0) { 088 serverIn.readFully(b,0,4); 089 l = ((int)b[2] &0xFF) << 8 | (int)b[3] &0xFF; 090 if (l == 0) { 091 serverOut.write(b); 092 serverOut.flush(); 093 } 094 } 095 return l; 096 } 097 protected int getHeaderLength() { 098 // GICC Channel does not support header 099 return 0; 100 } 101 protected void sendMessageHeader(ISOMsg m, int len) { 102 // GICC Channel does not support header 103 } 104} 105