Пример #1
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 = "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);
        }
Пример #2
0
        /*----< constructor >------------------------------------------*/

        /*
         * - starts listener listening on specified endpoint
         */
        public Comm(string baseAddress, int port)
        {
            rcvr = new Receiver();
            rcvr.start(baseAddress, port);
            sndr = new Sender(baseAddress, port);
        }