Esempio n. 1
0
        static void Main(string[] args)
        {
            List <string>      messages = new List <string>();
            WriteRequestParser re       = new WriteRequestParser();

            messages = re.parse("../../../writeRequest.xml");
            foreach (string message in messages)
            {
                Console.Write(message + "\n");
            }
        }
        static void Main(string[] args)
        {
            WriteRequestParser re = new WriteRequestParser();

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

            Console.Title = "Write Client";

            WriteClient clnt = new WriteClient();

            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;
            }
            clnt.request = re.parse("writeRequest.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;
                if (clnt.verbose == 1)
                {
                    Console.Write("\n  Sending: {0}", msg.content);
                }
                hrt.Start();
                if (!sndr.sendMessage(msg))
                {
                    break;
                }
                hrt.Stop();
                total += hrt.ElapsedMicroseconds;
                Thread.Sleep(100);
            }
            //hrt.Stop();

            /*Use the following for testing the client
             *
             * 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;
             * }
             *
             */
            Console.Write("\n  Total time taken for sending all write messages {0} microseconds\n", total);
            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.
            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");
        }