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 org.jpos.iso.*; 022 023import java.io.IOException; 024import java.net.ServerSocket; 025 026/** 027 * Implements an ISOChannel capable to exchange messages with 028 * ACI's BASE24[tm] over an X.25 link. 029 * 030 * An instance of this class exchanges messages by means of an 031 * intermediate 'port server' as described in the 032 * <a href="/doc/javadoc/overview-summary.html">Overview</a> page. 033 * @author apr@cs.com.uy 034 * 035 * @version $Id$ 036 * 037 * @see ISOMsg 038 * @see ISOException 039 * @see ISOChannel 040 */ 041@SuppressWarnings("deprecation") 042public class BASE24Channel extends BaseChannel { 043 /** 044 * Public constructor (used by Class.forName("...").newInstance()) 045 */ 046 public BASE24Channel () { 047 super(); 048 } 049 /** 050 * Construct client ISOChannel 051 * @param host server TCP Address 052 * @param port server port number 053 * @param p an ISOPackager 054 * @see ISOPackager 055 */ 056 public BASE24Channel (String host, int port, ISOPackager p) { 057 super(host, port, p); 058 } 059 /** 060 * Construct server ISOChannel 061 * @param p an ISOPackager 062 * @see ISOPackager 063 * @exception IOException 064 */ 065 public BASE24Channel (ISOPackager p) throws IOException { 066 super(p); 067 } 068 /** 069 * constructs a server ISOChannel associated with a Server Socket 070 * @param p an ISOPackager 071 * @param serverSocket where to accept a connection 072 * @exception IOException 073 * @see ISOPackager 074 */ 075 public BASE24Channel (ISOPackager p, ServerSocket serverSocket) 076 throws IOException 077 { 078 super(p, serverSocket); 079 } 080 /** 081 * @param m the Message to send (in this case it is unused) 082 * @param len message len (ignored) 083 * @exception IOException 084 */ 085 protected void sendMessageTrailler(ISOMsg m, int len) throws IOException { 086 serverOut.write (3); 087 } 088 /** 089 * @return a byte array with the received message 090 * @exception IOException 091 */ 092 protected byte[] streamReceive() throws IOException { 093 int i; 094 byte[] buf = new byte[4096]; 095 for (i=0; i<4096; i++) { 096 int c = serverIn.read(); 097 if (c == 0x3) 098 break; 099 buf[i] = (byte) c; 100 } 101 if (i == 4096) 102 throw new IOException("message too long"); 103 104 byte[] d = new byte[i]; 105 System.arraycopy(buf, 0, d, 0, i); 106 return d; 107 } 108}