Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Thread.Sleep(2000);
            Console.Write("\n  starting CommService client");
            Console.Write("\n =============================\n");
            Console.Title = "Reader Client";
            Client clnt = new Client();

            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.hrt.Start();
            rcvr.setTotalMessageSize(clnt.getMsgLen("XMLReader.xml"));
            clnt.readMsgTemplate("XMLReader.xml", sndr);
            while (true)
            {
                if (rcvr.getLastFlag())
                {
                    clnt.hrt.Stop();
                    break;
                }
            }
            ulong latency = clnt.hrt.ElapsedMicroseconds;

            clnt.travelLatency(latency, sndr);
            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
            rcvr.shutDown();
            sndr.shutdown();
            Console.Write("\n\n");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Thread.Sleep(1500);
            Console.Write("\n  starting CommService writer client");
            Console.Write("\n =======================================\n");
            Console.Write("\n XML for Reading template is XMLWriter.xml");
            Console.Write("\n =======================================\n");
            Console.Write("\n If Verbose switch is off, then all logs are logged into WPF Client/GUI.");
            Console.Write("\n =====================================================================\n");
            Console.Write("\n Demonstrating Requirement #4 by sending add/delete/edit/persist/augment messages from writer client to server.");
            Console.Write("\n Demonstrating Requirement #5 by taking format of request from XML and showing performance on GUI as well as on Console(If logging switch is on).");
            Console.Title = "Client #1";

            Client clnt = new Client();

            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.hrt.Start();
            rcvr.setTotalMessageSize(clnt.getMessageSize("XMLWriter.xml"));
            clnt.readMessageTemplates("XMLWriter.xml", sndr);
            while (true)
            {
                if (rcvr.getLastFlag())
                {
                    clnt.hrt.Stop();
                    break;
                }
            }
            ulong latency = clnt.hrt.ElapsedMicroseconds;
            int   lat     = Convert.ToInt32(latency);

            clnt.transportInformation(latency, sndr);
            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
            rcvr.shutDown();
            sndr.shutdown();
            Console.Write("\n\n");
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.Write("\n  Starting Writer client");
            Console.Write("\n =============================\n");
            Console.Title = "Writer";
            Client clnt = new Client();

            try
            {
                clnt.processCommandLine(args);
                string   localPort = Util.urlPort(clnt.localUrl);
                string   localAddr = Util.urlAddress(clnt.localUrl);
                Receiver rcvr      = new Receiver(localPort, localAddr);
                Sender   sndr      = new Sender(clnt.localUrl); // Sender needs localUrl for start message

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

                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.timer.Start();
                clnt.readMessageTemplates("XMLWriter.xml");
                if (clnt.listOfMsgs.Count() > 0)
                {
                    rcvr.setTotalMessageSize(clnt.getTotalNumberOfMessages(clnt.listOfMsgs));
                    clnt.processMessages(clnt.listOfMsgs, sndr);
                    while (true)
                    {
                        if (rcvr.getLastFlag())
                        {
                            clnt.timer.Stop();
                            break;
                        }
                    }
                }
                ulong latency = clnt.timer.ElapsedMicroseconds;
                clnt.sendPerformanceMessage(latency, sndr);
                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
                rcvr.shutDown();
                sndr.shutdown();
                Console.Write("\n\n");
            }
            catch (Exception e)
            {
                Console.Write("Invalid XMl file or some exception occured.");
                Console.Write("Exception : " + e.StackTrace);
                throw;
            }
        }