/*----< receive thread processing >----------------------------*/

        void threadProc()
        {
            while (true)
            {
                try
                {
                    CommMessage msg = comm_.getMessage();
                    Console.Write("\n  Received {0} message : {1}", msg.type.ToString(), msg.command.ToString());
                    CommMessage reply = dispatcher_.doCommand(msg.command, msg);
                    if (reply.command == Msg.Command.show)
                    {
                        reply.show(reply.arguments.Count < 7);
                        Console.Write("  -- no reply sent");
                    }
                    if (doReply(msg, reply))
                    {
                        comm_.postMessage(reply);
                    }
                }
                catch
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        /*----< processing for send thread >---------------------------*/

        /*
         * - send thread dequeues send message and posts to channel proxy
         * - thread inspects message and routes to appropriate specified endpoint
         */
        void threadProc()
        {
            while (true)
            {
                TestUtilities.putLine(string.Format("sender enqueuing message on thread {0}", Thread.CurrentThread.ManagedThreadId));

                CommMessage msg = sndQ.deQ();
                try
                {
                    if (msg.type == CommMessage.MessageType.closeSender)
                    {
                        TestUtilities.putLine("Sender send thread quitting");
                        close();
                        break;
                    }

                    /* MV: Commented out so we reconnect every time in case server or client
                     * disconnect. If not, channel goes into an unusable "faulted" state.
                     * Better solution is to check for faulted state exception and reconnect.
                     *
                     * Commented out, side-effect is that prior objects get deleted which causes
                     * postFile to fail.
                     */
                    if (msg.to == lastUrl)
                    {
                        channel.postMessage(msg);
                        lastError = "connected to " + msg.to;
                        TestUtilities.putLine(string.Format("\n  sending msg to {0}", msg.to));
                        if (ClientEnvironment.verbose)
                        {
                            msg.show(msg.arguments.Count < 7);
                        }
                    }
                    else
                    {
                        close();
                        if (!connect(msg.to))
                        {
                            CommMessage errMsg = new CommMessage(CommMessage.MessageType.commError);
                            errMsg.to       = msg.from;
                            errMsg.from     = msg.from;
                            errMsg.errorMsg = "can't connect to " + msg.to;
                            comm.postMessage(errMsg);
                            TestUtilities.putLine(string.Format("\n  can't connect to {0}", msg.to));
                            lastError = "can't connect to " + msg.to;
                            lastUrl   = "";
                            continue;
                        }
                        lastError = "connected to " + msg.to;
                        TestUtilities.putLine(string.Format("\n  {0}", lastError));
                        lastUrl = msg.to;
                        channel.postMessage(msg);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n--{0}", ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        /*----< processing for send thread >---------------------------*/

        /*
         * - send thread dequeues send message and posts to channel proxy
         * - thread inspects message and routes to appropriate specified endpoint
         */
        void threadProc()
        {
            while (true)
            {
                TestUtilities.putLine(string.Format("sender enqueuing message on thread {0}", Thread.CurrentThread.ManagedThreadId));

                CommMessage msg = sndQ.deQ();
                try
                {
                    if (msg.type == CommMessage.MessageType.closeSender)
                    {
                        TestUtilities.putLine("Sender send thread quitting");
                        close();
                        break;
                    }
                    if (msg.to == lastUrl)
                    {
                        channel.postMessage(msg);
                        lastError = "connected to " + msg.to;
                        TestUtilities.putLine(string.Format("\n  sending msg to {0}", msg.to));
                        if (ClientEnvironment.verbose)
                        {
                            msg.show(msg.arguments.Count < 7);
                        }
                    }
                    else
                    {
                        close();
                        if (!connect(msg.to))
                        {
                            CommMessage errMsg = new CommMessage(CommMessage.MessageType.commError);
                            errMsg.to       = msg.from;
                            errMsg.from     = msg.from;
                            errMsg.errorMsg = "can't connect to " + msg.to;
                            comm.postMessage(errMsg);
                            TestUtilities.putLine(string.Format("\n  can't connect to {0}", msg.to));
                            lastError = "can't connect to " + msg.to;
                            lastUrl   = "";
                            continue;
                        }
                        lastError = "connected to " + msg.to;
                        TestUtilities.putLine(string.Format("\n  {0}", lastError));
                        lastUrl = msg.to;
                        channel.postMessage(msg);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n--{0}", ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        /*----< test Sender and Receiver classes >---------------------*/

        public static bool testSndrRcvr()
        {
            TestUtilities.vbtitle("testing Sender & Receiver");

            bool     test = true;
            Receiver rcvr = new Receiver();

            rcvr.start("http://localhost", 8080);
            Sender sndr = new Sender("http://localhost", 8080);

            CommMessage sndMsg = new CommMessage(CommMessage.MessageType.request);

            sndMsg.command = Msg.Command.show;
            sndMsg.author  = "Jim Fawcett";
            sndMsg.to      = "http://localhost:8080/IPluggableComm";
            sndMsg.from    = "http://localhost:8080/IPluggableComm";

            sndr.postMessage(sndMsg);
            CommMessage rcvMsg;

            // get connection message
            rcvMsg = rcvr.getMessage();
            if (ClientEnvironment.verbose)
            {
                rcvMsg.show();
            }
            // get first info message
            rcvMsg = rcvr.getMessage();
            if (ClientEnvironment.verbose)
            {
                rcvMsg.show();
            }
            if (!compareMsgs(sndMsg, rcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "sndMsg equals rcvMsg");
            TestUtilities.putLine();

            sndMsg.type = CommMessage.MessageType.closeReceiver;
            sndr.postMessage(sndMsg);
            rcvMsg = rcvr.getMessage();
            if (ClientEnvironment.verbose)
            {
                rcvMsg.show();
            }
            if (!compareMsgs(sndMsg, rcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "Close Receiver");
            TestUtilities.putLine();

            sndMsg.type = CommMessage.MessageType.closeSender;
            if (ClientEnvironment.verbose)
            {
                sndMsg.show();
            }
            sndr.postMessage(sndMsg);
            // rcvr.getMessage() would fail because server has shut down
            // no rcvMsg so no compare

            TestUtilities.putLine("last message received\n");
            return(test);
        }
Exemplo n.º 5
0
        /*----< test Comm instance >-----------------------------------*/

        public static bool testComm()
        {
            TestUtilities.vbtitle("testing Comm");
            bool test = true;

            Comm        comm    = new Comm("http://localhost", 8081);
            CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request);

            csndMsg.command = Msg.Command.show;
            csndMsg.author  = "Jim Fawcett";
            csndMsg.to      = "http://localhost:8081/IPluggableComm";
            csndMsg.from    = "http://localhost:8081/IPluggableComm";

            comm.postMessage(csndMsg);
            CommMessage crcvMsg = comm.getMessage();

            if (ClientEnvironment.verbose)
            {
                crcvMsg.show();
            }

            crcvMsg = comm.getMessage();
            if (ClientEnvironment.verbose)
            {
                crcvMsg.show();
            }
            if (!compareMsgs(csndMsg, crcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "csndMsg equals crcvMsg");
            TestUtilities.putLine();

            TestUtilities.vbtitle("testing file transfer");

            bool testFileTransfer = true;

            List <string> names = getClientFileList();

            foreach (string name in names)
            {
                TestUtilities.putLine(string.Format("transferring file \"{0}\"", name));
                bool transferSuccess = comm.postFile(name);
                TestUtilities.checkResult(transferSuccess, "transfer");
            }

            foreach (string name in names)
            {
                if (!compareFileBytes(name))
                {
                    testFileTransfer = false;
                    break;
                }
            }
            TestUtilities.checkResult(testFileTransfer, "file transfers");
            TestUtilities.putLine();

            TestUtilities.vbtitle("test receiver close");
            csndMsg.type = CommMessage.MessageType.closeReceiver;
            comm.postMessage(csndMsg);
            crcvMsg = comm.getMessage();
            if (ClientEnvironment.verbose)
            {
                crcvMsg.show();
            }
            if (!compareMsgs(csndMsg, crcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "closeReceiver");
            TestUtilities.putLine();

            csndMsg.type = CommMessage.MessageType.closeSender;
            comm.postMessage(csndMsg);
            if (ClientEnvironment.verbose)
            {
                csndMsg.show();
            }
            // comm.getMessage() would fail because server has shut down
            // no rcvMsg so no compare

            TestUtilities.putLine("last message received\n");

            return(test && testFileTransfer);
        }