Exemple #1
0
        private void Command_ResponseReceived(object sender, StringResponseReceivedEventArgs e)
        {
            Log("Received CMD : " + e.ResponseMessage);

            //downloading
            if (e.ResponseMessage.Length == 1)
            {
                // this is a command from server
                if (e.ResponseMessage.Equals("a"))
                {
                    // start
                    _stopwatch.Reset();
                    _stopwatch.Start();
                    _packetCounter = 0;
                }
            }
            //uploading
            //else if (e.ResponseMessage.Length == 0)
            //{
            //	stopwatch.Stop();
            //	Log("Received completed.");
            //	Log("Total packets : " + packetCounter); // should equals to repeat
            //	Log("Packets length : " + bytesLength + " bytes");
            //	Log("Duration : " + stopwatch.ElapsedMilliseconds + " ms");
            //	Log("Size transfered : " + sizeTransfered + " bytes");
            //	Log("Bandwidth : " + MBps + " MB/s");
            //	Log("Bandwidth : " + Mbps + " Mb/s");
            //	Log("");
            //}
        }
Exemple #2
0
        private void CommandResponseReceived(object sender, StringResponseReceivedEventArgs e)
        {
            Log("Received : " + e.ResponseMessage);

            // Analyze command received(received list of server to connect to) ip:port
            // if download
            // connect to worker
            // ready for download
            // if upload
            // use this for upload
            // Connect to supplied list of server

            /*
             * var ip = new IPEndPoint[256];
             * ip[0].Address = IPAddress.Loopback;
             * ip[0].Port = 4504;
             * byte[] data = new byte[1048576]; // initialize 1MB data
             * Random random = new Random();
             * random.NextBytes(data);
             *
             * if (InitializeWorkerConnection(ip[0]))
             * {
             *      WorkerMessageSender[0].SendRequestMessage(data);
             * }
             */

            // test disconnect
            //if(CommandMessageSender.IsDuplexOutputChannelAttached)
            //	CommandMessageSender.DetachDuplexOutputChannel();
        }
        private void CommandResponseReceived(object sender, StringResponseReceivedEventArgs e)
        {
            Log("Received : " + e.ResponseMessage);

            // Analyze command received(received list of server to connect to) ip:port
            // if download
            // connect to worker
            // ready for download
            // if upload
            // use this for upload
            // Connect to supplied list of server

            /*
            var ip = new IPEndPoint[256];
            ip[0].Address = IPAddress.Loopback;
            ip[0].Port = 4504;
            byte[] data = new byte[1048576]; // initialize 1MB data
            Random random = new Random();
            random.NextBytes(data);

            if (InitializeWorkerConnection(ip[0]))
            {
                WorkerMessageSender[0].SendRequestMessage(data);
            }
            */

            // test disconnect
            //if(CommandMessageSender.IsDuplexOutputChannelAttached)
            //	CommandMessageSender.DetachDuplexOutputChannel();
        }
        public void WrapUnwrapMessage()
        {
            // Wrapped/unwrapped channels
            string aChannel1Id = "Channel1Id";
            string aChannel2Id = "Channel2Id";

            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();

            IDuplexStringMessageReceiver aStringMessageReceiver1 = aStringMessagesFactory.CreateDuplexStringMessageReceiver();
            IDuplexStringMessageReceiver aStringMessageReceiver2 = aStringMessagesFactory.CreateDuplexStringMessageReceiver();

            IDuplexStringMessageSender aStringMessageSender1 = aStringMessagesFactory.CreateDuplexStringMessageSender();
            IDuplexStringMessageSender aStringMessageSender2 = aStringMessagesFactory.CreateDuplexStringMessageSender();

            // Attach input channels to string receivers.
            aStringMessageReceiver1.AttachDuplexInputChannel(myMessagingForUnwrapper.CreateDuplexInputChannel(aChannel1Id));
            aStringMessageReceiver2.AttachDuplexInputChannel(myMessagingForUnwrapper.CreateDuplexInputChannel(aChannel2Id));

            // Connect string senders with the channel wrapper.
            myDuplexChannelWrapper.AttachDuplexInputChannel(myMessagingForWrapper.CreateDuplexInputChannel(aChannel1Id));
            myDuplexChannelWrapper.AttachDuplexInputChannel(myMessagingForWrapper.CreateDuplexInputChannel(aChannel2Id));
            aStringMessageSender1.AttachDuplexOutputChannel(myMessagingForWrapper.CreateDuplexOutputChannel(aChannel1Id));
            aStringMessageSender2.AttachDuplexOutputChannel(myMessagingForWrapper.CreateDuplexOutputChannel(aChannel2Id));

            // Connect wrapper and unwrapper to global channels.
            myDuplexChannelUnwrapper.AttachDuplexInputChannel(myDuplexGlobalInputChannel);
            myDuplexChannelWrapper.AttachDuplexOutputChannel(myDuplexGlobalOutputChannel);


            StringRequestReceivedEventArgs aReceivedMessage1 = null;

            aStringMessageReceiver1.RequestReceived += (x, y) =>
            {
                aReceivedMessage1 = y;
                aStringMessageReceiver1.SendResponseMessage(y.ResponseReceiverId, "Response1");
            };

            StringRequestReceivedEventArgs aReceivedMessage2 = null;

            aStringMessageReceiver2.RequestReceived += (x, y) =>
            {
                aReceivedMessage2 = y;
                aStringMessageReceiver2.SendResponseMessage(y.ResponseReceiverId, "Response2");
            };

            StringResponseReceivedEventArgs aReceivedResponse1 = null;

            aStringMessageSender1.ResponseReceived += (x, y) =>
            {
                aReceivedResponse1 = y;
            };

            StringResponseReceivedEventArgs aReceivedResponse2 = null;

            aStringMessageSender2.ResponseReceived += (x, y) =>
            {
                aReceivedResponse2 = y;
            };

            aStringMessageSender1.SendMessage("Message1");

            Assert.AreEqual("Message1", aReceivedMessage1.RequestMessage, "Message receiver 1 received incorrect message.");
            Assert.AreEqual("Response1", aReceivedResponse1.ResponseMessage, "Response receiver 1 received incorrect message.");
            Assert.IsNull(aReceivedMessage2, "Message receiver 2 should not receive a message.");
            Assert.IsNull(aReceivedResponse2, "Response receiver 2 should not receive a message.");

            string anAssociatedResponseReceiverId = myDuplexChannelUnwrapper.GetAssociatedResponseReceiverId(aReceivedMessage1.ResponseReceiverId);

            Assert.AreEqual(myDuplexChannelWrapper.AttachedDuplexOutputChannel.ResponseReceiverId, anAssociatedResponseReceiverId);


            aReceivedMessage1  = null;
            aReceivedResponse1 = null;

            aStringMessageSender2.SendMessage("Message2");

            Assert.AreEqual("Message2", aReceivedMessage2.RequestMessage, "Message receiver 2 received incorrect message.");
            Assert.AreEqual("Response2", aReceivedResponse2.ResponseMessage, "Response receiver 2 received incorrect message.");
            Assert.IsNull(aReceivedMessage1, "Message receiver 1 should not receive a message.");
            Assert.IsNull(aReceivedResponse1, "Response receiver 1 should not receive a message.");
        }
Exemple #5
0
        private void Command_ResponseReceived(object sender, StringResponseReceivedEventArgs e)
        {
            Log("Received CMD : " + e.ResponseMessage);

            //downloading
            if (e.ResponseMessage.Length == 1)
            {
                // this is a command from server
                if (e.ResponseMessage.Equals("a"))
                {
                    // start
                    _stopwatch.Reset();
                    _stopwatch.Start();
                    _packetCounter = 0;
                }
            }
            //uploading
            //else if (e.ResponseMessage.Length == 0)
            //{
            //	stopwatch.Stop();
            //	Log("Received completed.");
            //	Log("Total packets : " + packetCounter); // should equals to repeat
            //	Log("Packets length : " + bytesLength + " bytes");
            //	Log("Duration : " + stopwatch.ElapsedMilliseconds + " ms");
            //	Log("Size transfered : " + sizeTransfered + " bytes");
            //	Log("Bandwidth : " + MBps + " MB/s");
            //	Log("Bandwidth : " + Mbps + " Mb/s");
            //	Log("");
            //}
        }
Exemple #6
0
 // The method is called when a message from the desktop application is received.
 private void MessageReceived(object sender, StringResponseReceivedEventArgs e)
 {
     textBox2.Text = e.ResponseMessage;
 }