static void Main(string[] args)
        {
            ReadRequestParser re = new ReadRequestParser();

            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");

            Console.Title = "Read Client";

            ReadClient clnt = new ReadClient();

            clnt.processCommandLine(args);

            string   localPort = Util.urlPort(clnt.localUrl);
            string   localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr);

            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }

            Sender sndr = new Sender(clnt.localUrl); // Sender needs localUrl for start message

            Message msg = new Message();

            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;

            Console.Write("\n  sender's url is {0}", msg.fromUrl);
            Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);

            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();
                return;
            }

            //--------< read XML file, start high res timer, send messages, stop timer, log elapsed time to console >-----------
            clnt.request = re.parse("readRequest.xml");
            HiResTimer hrt   = new HiResTimer();
            ulong      total = 0;

            foreach (string i in clnt.request)
            {
                msg         = new Message();
                msg.fromUrl = clnt.localUrl;
                msg.toUrl   = clnt.remoteUrl;
                msg.content = i;
                Console.Write("\n  Sending: {0}", msg.content);
                hrt.Start();
                if (!sndr.sendMessage(msg))
                {
                    break;
                }
                hrt.Stop();
                total += hrt.ElapsedMicroseconds;
                Thread.Sleep(100);
            }
            hrt.Stop();


            //-------------< test stub >-----------

            /*
             * int numMsgs = 5;
             * int counter = 0;
             * while (true)
             * {
             *      msg.content = "Hello";
             *      Console.Write("\n  sending {0}", msg.content);
             *      if (!sndr.sendMessage(msg))
             *              return;
             *      Thread.Sleep(100);
             ++counter;
             *      if (counter >= numMsgs)
             *              break;
             * }
             *
             */

            msg         = new Message();
            msg.fromUrl = clnt.localUrl;
            msg.toUrl   = clnt.remoteUrl;
            msg.content = "done";
            sndr.sendMessage(msg);

            // Wait for user to press a key to quit.
            // Ensures that client has gotten all server replies.
            Console.Write("\n  Total time for sending all read messages: {0} microseconds", total);
            //Console.Write("\n  Average latency for sending all read messages: {0} microseconds", hrt.ElapsedMicroseconds);
            Util.waitForUser();

            // shut down this client's Receiver and Sender by sending close messages
            try { rcvr.shutDown();
                  sndr.shutdown(); }
            catch { Console.Write("\n  Problem with closing sender and/or receiver\n"); }

            Console.Write("\n\n");
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.Write("\n  starting Read Client for requirement #7");
            Console.Write("\n =============================\n");

            Console.Title = "ReadClient";

            ReadClient clnt = new ReadClient();
            clnt.processCommandLine(args);
            Console.Title = "ReadClient";

            string localPort = Util.urlPort(clnt.localUrl);
            string localAddr = Util.urlAddress(clnt.localUrl);
            Receiver rcvr = new Receiver(localPort, localAddr);
            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }

            Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message

            Message msg = new Message();
            msg.fromUrl = clnt.localUrl;
            msg.toUrl = clnt.remoteUrl;

            Console.Write("\n  sender's url is {0}", msg.fromUrl);
            Console.Write("\n  attempting to connect to {0}\n", msg.toUrl);

            if (!sndr.Connect(msg.toUrl))
            {
                Console.Write("\n  could not connect in {0} attempts", sndr.MaxConnectAttempts);
                sndr.shutdown();
                rcvr.shutDown();
                return;
            }

            XmlDocument doc = new XmlDocument();
            doc.Load("readClientTest.xml");
            XmlNodeList xmlnode = doc.GetElementsByTagName("Message");
            Stopwatch watch = new Stopwatch();

            watch.Start();//start watch
            while (true)//read and send messages
            {
                msg = new Message();
                msg.fromUrl = clnt.localUrl;
                msg.toUrl = clnt.remoteUrl;
                for (int i = 0; i < xmlnode.Count; i++)
                {
                    msg.content = "<?xml version=\"1.0\" encoding=\"utf - 8\" standalone=\"yes\"?>" + xmlnode[i].OuterXml;
                    Console.Write("\n  sending {0}\n", msg.content);
                    if (!sndr.sendMessage(msg))
                        return;
                    Thread.Sleep(100);
                }
                break;
            }
            msg.content = "done";
            sndr.sendMessage(msg);

            // Wait for user to press a key to quit.
            // Ensures that client has gotten all server replies.
            watch.Stop();
			string time = watch.ElapsedMilliseconds.ToString();
            Console.Write("Elapsed time: " + time + " millionsecondns\n\n");//print time elapsed
            Util.waitForUser();

            // shut down this client's Receiver and Sender by sending close messages
            rcvr.shutDown();
            sndr.shutdown();

            Console.Write("\n\n");
            
        }