Пример #1
0
        public static void  Main(System.String[] args)
        {
            if (args.Length != 2)
            {
                System.Console.Out.WriteLine("Usage: Genetibase.NuGenHL7.app.Initiator host port");
            }

            try
            {
                //set up connection to server
                System.String host = args[0];
                int           port = System.Int32.Parse(args[1]);

                Parser             parser     = new PipeParser();
                LowerLayerProtocol llp        = LowerLayerProtocol.makeLLP();
                NuGenConnection    connection = new NuGenConnection(parser, llp, new System.Net.Sockets.TcpClient(host, port));
                NuGenInitiator     initiator  = connection.Initiator;
                System.String      outText    = "MSH|^~\\&|||||||ACK^^ACK|||R|2.4|\rMSA|AA";

                //get a bunch of threads to send messages
                for (int i = 0; i < 1000; i++)
                {
                    SupportClass.ThreadClass sender = new SupportClass.ThreadClass(new System.Threading.ThreadStart(new AnonymousClassRunnable(parser, outText, initiator).Run));
                    sender.Start();
                }
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
Пример #2
0
 /// <summary>Creates a new instance of TwoPortService </summary>
 public NuGenTwoPortService(Parser parser, LowerLayerProtocol llp, int inboundPort, int outboundPort) : base(parser, llp)
 {
     inSockets         = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(20));
     outSockets        = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(20));
     this.inboundPort  = inboundPort;
     this.outboundPort = outboundPort;
 }
Пример #3
0
        /// <summary> Returns a Connection to the given address, opening this
        /// Connection if necessary. The given Parser will only be used if a new Connection
        /// is opened, so there is no guarantee that the Connection returnd will be using the
        /// Parser you provide.  If you need explicit access to the Parser the Connection
        /// is using, call <code>Connection.getParser()</code>.
        /// </summary>
        public virtual NuGenConnection attach(System.String host, int port, Parser parser, System.Type llpClass)
        {
            NuGenConnection conn = getExisting(host, port, parser.GetType(), llpClass);

            if (conn == null)
            {
                try
                {
                    //Parser p = (Parser) parserClass.newInstance();
                    LowerLayerProtocol llp = (LowerLayerProtocol)System.Activator.CreateInstance(llpClass);
                    conn = connect(host, port, parser, llp);
                }
                catch (System.InvalidCastException e)
                {
                    //Log.tryToLog(, "Problem opening new connection to " + host + " port " + port);
                    throw new NuGenHL7Exception("ClassCastException - need a LowerLayerProtocol class to get an Inititator", NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e);
                }
                catch (System.Exception e)
                {
                    //Log.tryToLog(e, "Problem opening new connection to " + host + " port " + port);
                    throw new NuGenHL7Exception("Can't connect to " + host + " port " + port + ": " + e.GetType().FullName + ": " + e.Message, NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e);
                }
            }
            incrementRefs(conn);
            return(conn);
        }
Пример #4
0
 /// <summary>Creates a new instance of Server </summary>
 public NuGenHL7Service(NuGenParser parser, LowerLayerProtocol llp)
 {
     connections = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
     listeners   = new System.Collections.ArrayList();
     this.parser = parser;
     this.llp    = llp;
     this.router = new NuGenMessageTypeRouter();
 }
Пример #5
0
		/// <summary>Creates a new instance of Server </summary>
		public NuGenHL7Service(NuGenParser parser, LowerLayerProtocol llp)
		{
			connections = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
			listeners = new System.Collections.ArrayList();
			this.parser = parser;
			this.llp = llp;
			this.router = new NuGenMessageTypeRouter();
		}
Пример #6
0
        /// <summary> Opens a connection to the given address, and stores it in the
        /// connections Hash.
        /// </summary>
        private NuGenConnection connect(System.String host, int port, Parser parser, LowerLayerProtocol llp)
        {
            System.Net.Sockets.TcpClient s = new System.Net.Sockets.TcpClient(host, port);
            NuGenConnection i = new NuGenConnection(parser, llp, s);

            connections[makeHashKey(host, port, parser.GetType(), llp.GetType())] = i;
            sockets[makeHashKey(host, port, parser.GetType(), llp.GetType())]     = s;
            return(i);
        }
Пример #7
0
        /// <summary> Creates a new instance of Connection, with inbound and outbound
        /// communication on a single port.
        /// </summary>
        public NuGenConnection(Parser parser, LowerLayerProtocol llp, System.Net.Sockets.TcpClient bidirectional)
        {
            init(parser);
            ackWriter  = llp.getWriter(bidirectional.GetStream());
            sendWriter = ackWriter;
            sockets.Add(bidirectional);
            NuGenReceiver r = new NuGenReceiver(this, llp.getReader(bidirectional.GetStream()));

            r.start();
            receivers.Add(r);
            this.initiator = new NuGenInitiator(this);
        }
Пример #8
0
        /// <summary> Creates a new instance of Connection, with inbound communication on one
        /// port and outbound on another.
        /// </summary>
        public NuGenConnection(Parser parser, LowerLayerProtocol llp, System.Net.Sockets.TcpClient inbound, System.Net.Sockets.TcpClient outbound)
        {
            init(parser);
            ackWriter  = llp.getWriter(inbound.GetStream());
            sendWriter = llp.getWriter(outbound.GetStream());
            sockets.Add(outbound);             //always add outbound first ... see getRemoteAddress()
            sockets.Add(inbound);
            NuGenReceiver inRec  = new NuGenReceiver(this, llp.getReader(inbound.GetStream()));
            NuGenReceiver outRec = new NuGenReceiver(this, llp.getReader(outbound.GetStream()));

            inRec.start();
            outRec.start();
            receivers.Add(inRec);
            receivers.Add(outRec);
            this.initiator = new NuGenInitiator(this);
        }
Пример #9
0
        public static void  Main(System.String[] args)
        {
            if (args.Length < 1 || args.Length > 2)
            {
                System.Console.Out.WriteLine("Usage: Genetibase.NuGenHL7.app.SimpleServer port_num [application_spec_file_name]");
                System.Environment.Exit(1);
            }

            int port = 0;

            try
            {
                port = System.Int32.Parse(args[0]);
            }
            catch (System.FormatException)
            {
                System.Console.Error.WriteLine("The given port (" + args[0] + ") is not an integer.");
                System.Environment.Exit(1);
            }

            System.IO.FileInfo appFile = null;
            if (args.Length == 2)
            {
                appFile = new System.IO.FileInfo(args[1]);
            }

            try
            {
                NuGenSimpleServer server = new NuGenSimpleServer(port, LowerLayerProtocol.makeLLP(), new PipeParser());
                if (appFile != null)
                {
                    server.loadApplicationsFromFile(appFile);
                }
                server.start();
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
Пример #10
0
        public static void  Main(System.String[] args)
        {
            if (args.Length < 2 || args.Length > 3)
            {
                System.Console.Out.WriteLine("Usage: Genetibase.NuGenHL7.app.TwoPortService inbound_port outbound_port [application_spec_file_name]");
                System.Environment.Exit(1);
            }

            int inPort  = 0;
            int outPort = 0;

            try
            {
                inPort  = System.Int32.Parse(args[0]);
                outPort = System.Int32.Parse(args[1]);
            }
            catch (System.FormatException)
            {
                System.Console.Error.WriteLine("One of the given ports (" + args[0] + " or " + args[1] + ") is not an integer.");
                System.Environment.Exit(1);
            }

            System.IO.FileInfo appFile = null;
            if (args.Length == 3)
            {
                appFile = new System.IO.FileInfo(args[2]);
            }

            try
            {
                NuGenTwoPortService server = new NuGenTwoPortService(new PipeParser(), LowerLayerProtocol.makeLLP(), inPort, outPort);
                if (appFile != null)
                {
                    server.loadApplicationsFromFile(appFile);
                }
                server.start();
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
Пример #11
0
		/// <summary> Opens a connection to the given address, and stores it in the 
		/// connections Hash. 
		/// </summary>
		private NuGenConnection connect(System.String host, int port, Parser parser, LowerLayerProtocol llp)
		{
			System.Net.Sockets.TcpClient s = new System.Net.Sockets.TcpClient(host, port);
			NuGenConnection i = new NuGenConnection(parser, llp, s);
			connections[makeHashKey(host, port, parser.GetType(), llp.GetType())] = i;
			sockets[makeHashKey(host, port, parser.GetType(), llp.GetType())] = s;
			return i;
		}
Пример #12
0
		/// <summary> Creates a new instance of SimpleServer that listens
		/// </summary>
		public NuGenSimpleServer(int port, LowerLayerProtocol llp, Parser parser):base(parser, llp)
		{
			this.port = port;
		}
Пример #13
0
 /// <summary> Creates a new instance of SimpleServer that listens
 /// </summary>
 public NuGenSimpleServer(int port, LowerLayerProtocol llp, Parser parser) : base(parser, llp)
 {
     this.port = port;
 }
Пример #14
0
		/// <summary> Creates a new instance of Connection, with inbound communication on one 
		/// port and outbound on another.
		/// </summary>
		public NuGenConnection(Parser parser, LowerLayerProtocol llp, System.Net.Sockets.TcpClient inbound, System.Net.Sockets.TcpClient outbound)
		{
			init(parser);
			ackWriter = llp.getWriter(inbound.GetStream());
			sendWriter = llp.getWriter(outbound.GetStream());
			sockets.Add(outbound); //always add outbound first ... see getRemoteAddress()
			sockets.Add(inbound);
			NuGenReceiver inRec = new NuGenReceiver(this, llp.getReader(inbound.GetStream()));
			NuGenReceiver outRec = new NuGenReceiver(this, llp.getReader(outbound.GetStream()));
			inRec.start();
			outRec.start();
			receivers.Add(inRec);
			receivers.Add(outRec);
			this.initiator = new NuGenInitiator(this);
		}
Пример #15
0
		/// <summary> Creates a new instance of Connection, with inbound and outbound 
		/// communication on a single port. 
		/// </summary>
		public NuGenConnection(Parser parser, LowerLayerProtocol llp, System.Net.Sockets.TcpClient bidirectional)
		{
			init(parser);
			ackWriter = llp.getWriter(bidirectional.GetStream());
			sendWriter = ackWriter;
			sockets.Add(bidirectional);
			NuGenReceiver r = new NuGenReceiver(this, llp.getReader(bidirectional.GetStream()));
			r.start();
			receivers.Add(r);
			this.initiator = new NuGenInitiator(this);
		}