/*----< 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;
                }
            }
        }
示例#2
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);
        }