Ejemplo n.º 1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //[STAThread]
        static void Main(string[] args)
        {
            Console.WriteLine("Is running.");
            VolatileStanSequencer _sequencer;
            Socket        _socket;
            AddressFamily _family;

            _sequencer = new VolatileStanSequencer();
            Iso8583Message echoMsg = new Iso8583Message(800);

            echoMsg.Fields.Add(Field3ProcCode, "990000");
            DateTime transmissionDate = DateTime.Now;

            echoMsg.Fields.Add(Field7TransDateTime, string.Format("{0}{1}", string.Format("{0:00}{1:00}", transmissionDate.Month, transmissionDate.Day), string.Format("{0:00}{1:00}{2:00}", transmissionDate.Hour, transmissionDate.Minute, transmissionDate.Second)));
            echoMsg.Fields.Add(Field11Trace, _sequencer.Increment().ToString());
            echoMsg.Fields.Add(Field24Nii, "101");
            echoMsg.Fields.Add(Field41TerminalCode, "12131415");
            echoMsg.Fields.Add(Field42MerchantCode, "000000852963  ");
            IMessageFormatter _formatter = new Iso8583Bin1987MessageFormatter();

            //formatterContext.GetData();
            echoMsg.Formatter = _formatter;
            //echoMsg.Formatter.Format(echoMsg, ref formatterContext);

            byte[] bBufferRecive;
            byte[] bBuffer = echoMsg.GetBytes();
            byte[] bHeader = Hex2Byte("6000018000");
            int    iTalla  = bBuffer.Length + bHeader.Length;

            byte[] bTalla = Hex2Byte(Convert.ToString(iTalla, 16).PadLeft(4, '0'));
            _family = AddressFamily.InterNetwork;
            _socket = new Socket(_family, SocketType.Stream, ProtocolType.Tcp);
            _socket.Connect("192.168.123.39", 9004);
            _socket.Send(bTalla);
            _socket.Send(bHeader);
            _socket.Send(bBuffer);
            Console.WriteLine(Byte2Hex(bTalla) + Byte2Hex(bHeader) + Byte2Hex(bBuffer));
            _socket.ReceiveTimeout = 10000;
            bBufferRecive          = new byte[_socket.ReceiveBufferSize];
            _socket.Receive(bBufferRecive);
            Hashtable ISO = TransaformaIso(bBufferRecive);

            byte[] bBody = (byte[])ISO["Body"];
            //FormatterContext formatterContext = new FormatterContext(FormatterContext.DefaultBufferSize);
            //formatterContext.Write(bBody);
            ParserContext _parserContext = new ParserContext(bBody.Length);

            _parserContext.Initialize();
            _parserContext.ResizeBuffer(bBody.Length);
            _parserContext.Write(bBody);

            Iso8583Message echoMsgResp = (Iso8583Message)echoMsg.Formatter.Parse(ref _parserContext);

            //echoMsg.Formatter.Format(echoMsg, ref formatterContext);
            Console.WriteLine(Byte2Hex(bBody));
            Console.WriteLine(echoMsgResp.ToString());
            _socket.Close();
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="hostName">
        /// The server hosting the acquirer.
        /// </param>
        /// <param name="localInterface">
        /// The ip address of the local interface to listen.
        /// </param>
        public Engine()
        {
            try
            {
                _forwarder = new MyBridge();
                _sequencer = new VolatileStanSequencer();

                // Create a server to listen internal clients requests (internal clients are clients that connect
                //from viacard itself e.g loading, settlement, reversal. etc.).
                TcpListener inlistener = new TcpListener(PinConfigurationManager.FepConfig.InternalServerPort);
                inlistener.LocalInterface = PinConfigurationManager.FepConfig.BridgeHostIp;
                _forwarder.InternalServer = new Trx.Messaging.FlowControl.Server("InternalServer",
                                                                                 inlistener, new BasicServerPeerManager());

                // Create a server to listen external clients requests (external clients are the node connections).
                TcpListener exlistener = new TcpListener(PinConfigurationManager.FepConfig.ExternalServerPort);
                exlistener.LocalInterface = PinConfigurationManager.FepConfig.BridgeHostIp;
                _forwarder.ExternalServer = new Trx.Messaging.FlowControl.Server("ExternalServer",
                                                                                 exlistener, new BasicServerPeerManager2());


                // Configure the internal server to accept up to 4 clients (i.e 4 connections from ViaCard at a time).
                //_forwarder.InternalServer.Listener.ChannelPool = new BasicChannelPool(
                //    new TwoBytesNboHeaderChannel(new Iso8583Ascii1987BinaryBitmapMessageFormatter()),
                //    1000);

                //_forwarder.ExternalServer.Listener.ChannelPool = new BasicChannelPool(
                //    new TwoBytesNboHeaderChannel(new Iso8583Ascii1987BinaryBitmapMessageFormatter()),
                //    1000);
                _forwarder.InternalServer.Listener.ChannelPool = new BasicChannelPool(
                    new TwoBytesNboHeaderChannel(new Iso8583Ascii1987BinaryBitmapMessageFormatter()),
                    1000);

                _forwarder.ExternalServer.Listener.ChannelPool = new BasicChannelPool(
                    new TwoBytesNboHeaderChannel(new Iso8583Ascii1987BinaryBitmapMessageFormatter()),
                    1000);


                // Instruct the server peer manager to deliver all the received
                // messages (from all its peers) to the forwarder.
                _forwarder.InternalServer.PeerManager.MessageProcessor = new InternalServerProcessor(_forwarder);
                _forwarder.ExternalServer.PeerManager.MessageProcessor = new ExternalServerProcessor(_forwarder);
            }
            catch (Exception ex) { new PANE.ERRORLOG.Error().LogToFile(ex); }
        }