예제 #1
0
        private void OpenConnectionBtn_Click(object sender, EventArgs e)
        {
            if (!mySender.IsDuplexOutputChannelAttached)
            {
                // The output channel is not attached yet.
                // So attach the output channel and be able to send
                // request messagas and receive response messages.
                IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory()
                {
                    // Set to receive messages in the main UI thread.
                    // Note: if this is not set then methods OnResponseReceived and
                    //       OnConnectionClosed would not be called from main UI thread
                    //       but from a listener thread.
                    OutputChannelThreading = new WinFormsDispatching(this)
                };
                IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8033/");
                mySender.AttachDuplexOutputChannel(anOutputChannel);

                ConnectionStatusLabel.Text = "Client Connected";
            }
            else if (!mySender.AttachedDuplexOutputChannel.IsConnected)
            {
                // The output channel is attached but the client got disconnected.
                // So jut reopen the connection.
                mySender.AttachedDuplexOutputChannel.OpenConnection();

                ConnectionStatusLabel.Text = "Client Connected";
            }
        }
예제 #2
0
        private bool Command_Initialize()
        {
            // Create duplex message sender.
            // It can send messages and also receive messages.
            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();

            Command_MessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender();
            Command_MessageSender.ResponseReceived += Command_ResponseReceived;

            // Create TCP based messaging.
            IMessagingSystemFactory aMessaging           = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4502/");

            // Attach the duplex output channel to the message sender
            // and be able to send messages and receive messages.
            try
            {
                Command_MessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);
            }
            catch (Exception e)
            {
                Log(e.Message);
            }

            if (Command_MessageSender.IsDuplexOutputChannelAttached)
            {
                Log("Initialized connection.");
                return(true);
            }
            else
            {
                Log("Unable to initialize connection");
                return(false);
            }
        }
        public Main()
        {
            try
            {
                InitializeComponent();
                ProcessFile();
                WriteFile();
                MessageBox.Show("Done!");
                return;
                _mMouseHookManager = new MouseHookListener(new GlobalHooker()) {Enabled = true};
                _mMouseHookManager.MouseUp += mMouseHookManager_MouseUp;

                ReadKeyFile(Properties.Settings.Default.KeyPath);

                IDuplexTypedMessagesFactory aSenderFactory = new DuplexTypedMessagesFactory();
                _mySender = aSenderFactory.CreateDuplexTypedMessageSender<AppQA, MyResponse>();

                IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
                IDuplexOutputChannel anOutputChannel =
                    aMessaging.CreateDuplexOutputChannel("tcp://" + Properties.Settings.Default.IpAddress + ":8060/");

                // Attach the input channel and start to listen to messages.
                _mySender.AttachDuplexOutputChannel(anOutputChannel);
            }
            catch (Exception exception)
            {
                WriteAnswer(Properties.Settings.Default.AnswerPath, exception.Message);
            }
        }
예제 #4
0
        public Form1()
        {
            InitializeComponent();

            // Create ProtoBuf serializer.
            mySerializer = new ProtoBufSerializer();

            // Create the broker client that will receive notification messages.
            IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory(mySerializer);
            myBrokerClient = aBrokerFactory.CreateBrokerClient();
            myBrokerClient.BrokerMessageReceived += OnNotificationMessageReceived;

            // Create the Tcp messaging for the communication with the publisher.
            // Note: For the interprocess communication you can use: Tcp, NamedPipes and Http.
            IMessagingSystemFactory aMessagingFactory = new TcpMessagingSystemFactory();

            // Create duplex output channel for the communication with the publisher.
            // Note: The duplex output channel can send requests and receive responses.
            //       In our case, the broker client will send requests to subscribe/unsubscribe
            //       and receive notifications as response messages.
            myOutputChannel = aMessagingFactory.CreateDuplexOutputChannel("tcp://127.0.0.1:7091/");

            // Attach the output channel to the broker client
            myBrokerClient.AttachDuplexOutputChannel(myOutputChannel);
        }
예제 #5
0
        public void ClientReceiveTimeout()
        {
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory()
            {
                ReceiveTimeout = TimeSpan.FromMilliseconds(1000)
            };
            IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8046/");
            IDuplexInputChannel  anInputChannel  = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8046/");

            try
            {
                ManualResetEvent aConnectionClosed = new ManualResetEvent(false);
                anOutputChannel.ConnectionClosed += (x, y) =>
                {
                    EneterTrace.Info("Connection closed.");
                    aConnectionClosed.Set();
                };

                anInputChannel.StartListening();
                anOutputChannel.OpenConnection();

                EneterTrace.Info("Connection opened.");

                // According to set receive timeout the client should get disconnected within 1 second.
                //aConnectionClosed.WaitOne();
                Assert.IsTrue(aConnectionClosed.WaitOne(3000));
            }
            finally
            {
                anOutputChannel.CloseConnection();
                anInputChannel.StopListening();
            }
        }
예제 #6
0
        private bool InitializeWorkerConnection()
        {
            // Create TCP messaging
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();

            Worker4504OutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4504/");

            // Subscribe to response messages.
            Worker4504OutputChannel.ConnectionClosed        += Worker4504OutputChannel_ConnectionClosed;
            Worker4504OutputChannel.ConnectionOpened        += Worker4504OutputChannel_ConnectionOpened;
            Worker4504OutputChannel.ResponseMessageReceived += Worker4504OutputChannel_ResponseMessageReceived;

            // Open connection and be able to send messages and receive response messages.
            Worker4504OutputChannel.OpenConnection();
            Log("Channel id : " + Worker4504OutputChannel.ChannelId);

            // Send a message.
            byte[] data = new byte[1048576];             // initialize 1MB data
            //byte[] data = new byte[10]; // initialize 1MB data
            Random random = new Random();

            random.NextBytes(data);
            Worker4504OutputChannel.SendMessage(data);
            Log("Sent data length : " + data.Length);

            // Close connection.
            //Worker4504OutputChannel.CloseConnection();

            return(true);
        }
예제 #7
0
        public void MaxAmountOfConnections()
        {
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory()
            {
                MaxAmountOfConnections = 2
            };
            IDuplexOutputChannel anOutputChannel1 = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8049/");
            IDuplexOutputChannel anOutputChannel2 = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8049/");
            IDuplexOutputChannel anOutputChannel3 = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8049/");
            IDuplexInputChannel  anInputChannel   = aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8049/");

            try
            {
                ManualResetEvent aConnectionClosed = new ManualResetEvent(false);
                anOutputChannel3.ConnectionClosed += (x, y) =>
                {
                    EneterTrace.Info("Connection closed.");
                    aConnectionClosed.Set();
                };


                anInputChannel.StartListening();
                anOutputChannel1.OpenConnection();
                anOutputChannel2.OpenConnection();
                anOutputChannel3.OpenConnection();

                if (!aConnectionClosed.WaitOne(1000))
                {
                    Assert.Fail("Third connection was not closed.");
                }

                Assert.IsTrue(anOutputChannel1.IsConnected);
                Assert.IsTrue(anOutputChannel2.IsConnected);
                Assert.IsFalse(anOutputChannel3.IsConnected);
            }
            finally
            {
                anOutputChannel1.CloseConnection();
                anOutputChannel2.CloseConnection();
                anOutputChannel3.CloseConnection();
                anInputChannel.StopListening();
            }
        }
        public void Setup()
        {
            string aPort     = RandomPortGenerator.Generate();
            string anAddress = "tcp://127.0.0.1:" + aPort + "/";

            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();

            InputChannel  = aMessaging.CreateDuplexInputChannel(anAddress);
            OutputChannel = aMessaging.CreateDuplexOutputChannel(anAddress);

            DuplexTypedMessagesFactory = new DuplexTypedMessagesFactory();
        }
예제 #9
0
        public ChannelWrapper()
        {
            IMessagingSystemFactory anInternalMessaging = new SynchronousMessagingSystemFactory();

            // The service receives messages via one channel (i.e. it listens on one address).
            // The incoming messages are unwrapped on the server side.
            // Therefore the client must use wrapper to send messages via one channel.
            IChannelWrapperFactory aChannelWrapperFactory = new ChannelWrapperFactory();

            myDuplexChannelWrapper = aChannelWrapperFactory.CreateDuplexChannelWrapper();


            // To connect message senders and the wrapper with duplex channels we can use the following helper class.
            IConnectionProviderFactory aConnectionProviderFactory = new ConnectionProviderFactory();
            IConnectionProvider        aConnectionProvider        = aConnectionProviderFactory.CreateConnectionProvider(anInternalMessaging);


            // Factory to create message senders.
            // Sent messages will be serialized in Xml.
            IDuplexTypedMessagesFactory aCommandsFactory = new DuplexTypedMessagesFactory();

            plusSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>();
            plusSender.ResponseReceived += (s, e) => {
                Console.WriteLine("CW.V+: " + e.ResponseMessage.Value);
            };
            // attach method handling the request
            aConnectionProvider.Connect(myDuplexChannelWrapper, plusSender, "plus"); // attach the input channel to get messages from unwrapper

            minusSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>();
            minusSender.ResponseReceived += (s, e) => {
                Console.WriteLine("CW.V-: " + e.ResponseMessage.Value);
            };
            // attach method handling the request
            aConnectionProvider.Connect(myDuplexChannelWrapper, minusSender, "minus"); // attach the input channel to get messages from unwrapper

            dotSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>();
            dotSender.ResponseReceived += (s, e) => {
                Console.WriteLine("CW.V.: " + e.ResponseMessage.Value);
            };
            // attach method handling the request
            aConnectionProvider.Connect(myDuplexChannelWrapper, dotSender, "dot"); // attach the input channel to get messages from unwrapper

            IMessagingSystemFactory aTcpMessagingSystem = new TcpMessagingSystemFactory();

            // Create output channel to send requests to the service.
            IDuplexOutputChannel anOutputChannel = aTcpMessagingSystem.CreateDuplexOutputChannel("tcp://127.0.0.1:8091/");

            // Attach the output channel to the wrapper - so that we are able to send messages
            // and receive response messages.
            // Note: The service has the coresponding unwrapper.
            myDuplexChannelWrapper.AttachDuplexOutputChannel(anOutputChannel);
        }
예제 #10
0
        public void Openconnection()
        {
            // Create message sender sending request messages of type Person and receiving responses of type string.
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();

            myMessageSender = aTypedMessagesFactory.CreateDuplexTypedMessageSender <string, Person>();
            myMessageSender.ResponseReceived += OnResponseReceived;
            // Create messaging based on TCP.
            IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    anOutputChannel         = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://127.0.0.1:8094/");

            // Attach output channel and be able to send messages and receive response messages.
            myMessageSender.AttachDuplexOutputChannel(anOutputChannel);
        }
예제 #11
0
파일: Form1.cs 프로젝트: jmmccota/SD-Tp3
 private void button2_Click(object sender, EventArgs e)
 {
     TcpMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
     IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + tbIP.Text + ":" + tbPorta.Text + "/");//ip local e porta do servidor
     myRpcClient.AttachDuplexOutputChannel(anOutputChannel);
     txtCliente.Enabled = true;
     txtCod.Enabled = true;
     txtValor.Enabled = true;
     SumButton.Enabled = true;
     button1.Enabled = true;
     button2.Enabled = false;
     tbPorta.Enabled = false;
     tbIP.Enabled = false;
 }
예제 #12
0
        public void OpenConnection()
        {
            // Establish connection with load scheduling module
            IMessagingSystemFactory     myMessaging     = new TcpMessagingSystemFactory();
            IDuplexOutputChannel        anOutputChannel = myMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8060/");
            IDuplexTypedMessagesFactory aSenderFactory  = new DuplexTypedMessagesFactory();

            mySender = aSenderFactory.CreateDuplexTypedMessageSender <double, Range>();

            // Event handler on receipt of response
            mySender.ResponseReceived += OnResponseReceived;

            // Attach the output channel to send messages and receive responses
            mySender.AttachDuplexOutputChannel(anOutputChannel);
        }
예제 #13
0
 public void init()
 {
     try
     {
         IRpcFactory rpcFactory = new RpcFactory();
         RpcObj = rpcFactory.CreateClient<ILeiloeiro>();
         TcpMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
         IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + IP + ":" + Porta + "/");//ip local e porta do servidor
         RpcObj.AttachDuplexOutputChannel(anOutputChannel);
     }
     catch (Exception ex)
     {
         throw new Exception("Erro: É necessario iniciar o servidor - " + ex.Message);
     }
 }
예제 #14
0
        public TalkFlow()
        {
            IRpcFactory factory = new RpcFactory();
            var         client  = factory.CreateClient <ITalk>();

            TcpMessagingSystemFactory messaging       = new TcpMessagingSystemFactory();
            IDuplexOutputChannel      anOutputChannel = messaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8045/");

            client.AttachDuplexOutputChannel(anOutputChannel);

            string sentence = "";

            while ((sentence = Console.ReadLine()) != "stop")
            {
                client.Proxy.Talk("Client A", sentence);
            }
        }
예제 #15
0
        // The method is called when the button to send message is clicked.
        private void SendMessage_Click(object sender, RoutedEventArgs e)
        {
            // Create message sender sending request messages of type Person and receiving responses of type string.
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();

            myMessageSender = aTypedMessagesFactory.CreateDuplexTypedMessageSender <byte[], byte[]>();
            myMessageSender.ResponseReceived += ResponseReceived;

            // Create messaging based on TCP.
            IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    aDuplexOutputChannel    = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/");

            // Attach output channel and be able to send messages and receive response messages.
            myMessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);

            myMessageSender.SendRequestMessage(GetBytes(textBox1.Text));
        }
예제 #16
0
        public MainPage()
        {
            InitializeComponent();

            // Create duplex message sender.
            // It can send messages and also receive messages.
            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();
            myMessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender();
            myMessageSender.ResponseReceived += MessageReceived;

            // Create TCP based messaging.
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            IDuplexOutputChannel aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/");

            // Attach the duplex output channel to the message sender
            // and be able to send messages and receive messages.
            myMessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);
        }
예제 #17
0
        public Form1()
        {
            InitializeComponent();

            // Create ProtoBuf serializer.
            mySerializer = new ProtoBufSerializer();

            // Create broker client responsible for sending messages to the broker.
            IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory(mySerializer);
            myBrokerClient = aBrokerFactory.CreateBrokerClient();

            // Create output channel to send messages via Tcp.
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            myOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:7091/");

            // Attach the output channel to the broker client to be able to send messages.
            myBrokerClient.AttachDuplexOutputChannel(myOutputChannel);
        }
예제 #18
0
        public void OpenConnection()
        {
            // Create TCP messaging for the communication.
            // Note: Requests are sent to the balancer that will forward them
            //       to available services.
            IMessagingSystemFactory myMessaging     = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    anOutputChannel = myMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8060/");

            // Create sender to send requests.
            IDuplexTypedMessagesFactory aSenderFactory = new DuplexTypedMessagesFactory();

            mySender = aSenderFactory.CreateDuplexTypedMessageSender <double, Range>();

            // Subscribe to receive response messages.
            mySender.ResponseReceived += OnResponseReceived;

            // Attach the output channel and be able to send messages and receive responses.
            mySender.AttachDuplexOutputChannel(anOutputChannel);
        }
예제 #19
0
        public void ConnectionTimeout()
        {
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory()
            {
                ConnectTimeout = TimeSpan.FromMilliseconds(1000)
            };

            // Nobody is listening on this address.
            IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://109.74.151.135:8045/");

            ManualResetEvent aConnectionCompleted = new ManualResetEvent(false);

            try
            {
                // Start opening in another thread to be able to measure
                // if the timeout occured with the specified time.
                Exception anException = null;
                ThreadPool.QueueUserWorkItem(x =>
                {
                    try
                    {
                        anOutputChannel.OpenConnection();
                    }
                    catch (Exception err)
                    {
                        anException = err;
                    }
                    aConnectionCompleted.Set();
                });

                if (aConnectionCompleted.WaitOne(1500))
                {
                }

                Assert.AreEqual(typeof(TimeoutException), anException);
            }
            finally
            {
                anOutputChannel.CloseConnection();
            }
        }
예제 #20
0
        private void OpenConnection()
        {
            // Create Protocol Buffers serializer.
            ISerializer aSerializer = new ProtoBufSerializer();

            // Create the synchronous message sender.
            // It will wait max 5 seconds for the response.
            // To wait infinite time use TimeSpan.FromMiliseconds(-1) or
            // default constructor new DuplexTypedMessagesFactory()
            IDuplexTypedMessagesFactory aSenderFactory =
                new DuplexTypedMessagesFactory(TimeSpan.FromSeconds(5), aSerializer);
            mySender = aSenderFactory.CreateSyncDuplexTypedMessageSender<ResponseMessage, RequestMessage>();

            // Use TCP for the communication.
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            IDuplexOutputChannel anOutputChannel =
                aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/");

            // Attach the output channel and be able to send messages
            // and receive response messages.
            mySender.AttachDuplexOutputChannel(anOutputChannel);
        }
예제 #21
0
        public MainWindow()
        {
            InitializeComponent();
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();

            mySender = aTypedMessagesFactory.CreateDuplexTypedMessageSender <MyResponse, MyRequest>();
            mySender.ResponseReceived += OnResponseReceived;

            // Create messaging based on TCP.
            IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    anOutputChannel         = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://192.168.2.9:8060/");

            // Attach output channel and be able to send messages and receive response messages.
            mySender.AttachDuplexOutputChannel(anOutputChannel);
            MyRequest test = new MyRequest {
                side = "L", strength = 10
            };

            mySender.SendRequestMessage(test);
            MyRequest reset = new MyRequest {
                side = "L", strength = 0
            };

            mySender.SendRequestMessage(reset);
            try
            {
                USBInterface usb = new USBInterface("vid_044f", "pid_b108");
                usb.Connect();
                usb.enableUsbBufferEvent(new System.EventHandler(myEventCacher));
                usb.startRead();

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #22
0
        private bool Worker4504_Initialize()
        {
            // Create TCP messaging
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();

            Worker4504_OutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4504/");

            // Subscribe to response messages.
            Worker4504_OutputChannel.ConnectionClosed        += Worker4504_ConnectionClosed;
            Worker4504_OutputChannel.ConnectionOpened        += Worker4504_ConnectionOpened;
            Worker4504_OutputChannel.ResponseMessageReceived += Worker4504_ResponseMessageReceived;

            // Open connection and be able to send messages and receive response messages.
            Worker4504_OutputChannel.OpenConnection();

            if (Worker4504_OutputChannel.IsConnected)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #23
0
        private bool Worker4504_Initialize()
        {
            // Create TCP messaging
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            Worker4504_OutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4504/");

            // Subscribe to response messages.
            Worker4504_OutputChannel.ConnectionClosed += Worker4504_ConnectionClosed;
            Worker4504_OutputChannel.ConnectionOpened += Worker4504_ConnectionOpened;
            Worker4504_OutputChannel.ResponseMessageReceived += Worker4504_ResponseMessageReceived;

            // Open connection and be able to send messages and receive response messages.
            Worker4504_OutputChannel.OpenConnection();

            if (Worker4504_OutputChannel.IsConnected)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
예제 #24
0
        private bool Command_Initialize()
        {
            // Create duplex message sender.
            // It can send messages and also receive messages.
            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();
            Command_MessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender();
            Command_MessageSender.ResponseReceived += Command_ResponseReceived;

            // Create TCP based messaging.
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            IDuplexOutputChannel aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4502/");

            // Attach the duplex output channel to the message sender
            // and be able to send messages and receive messages.
            try
            {
                Command_MessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);
            }
            catch (Exception e)
            {
                Log(e.Message);
            }

            if (Command_MessageSender.IsDuplexOutputChannelAttached)
            {
                Log("Initialized connection.");
                return true;
            }
            else
            {
                Log("Unable to initialize connection");
                return false;
            }
        }
        private bool InitializeWorkerConnection()
        {
            // Create TCP messaging
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            Worker4504OutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4504/");

            // Subscribe to response messages.
            Worker4504OutputChannel.ConnectionClosed += Worker4504OutputChannel_ConnectionClosed;
            Worker4504OutputChannel.ConnectionOpened += Worker4504OutputChannel_ConnectionOpened;
            Worker4504OutputChannel.ResponseMessageReceived += Worker4504OutputChannel_ResponseMessageReceived;

            // Open connection and be able to send messages and receive response messages.
            Worker4504OutputChannel.OpenConnection();
            Log("Channel id : " + Worker4504OutputChannel.ChannelId);

            // Send a message.
            byte[] data = new byte[1048576]; // initialize 1MB data
            //byte[] data = new byte[10]; // initialize 1MB data
            Random random = new Random();
            random.NextBytes(data);
            Worker4504OutputChannel.SendMessage(data);
            Log("Sent data length : " + data.Length);

            // Close connection.
            //Worker4504OutputChannel.CloseConnection();

            return true;
        }
        // The method is called when the button to send message is clicked.
        private void SendMessage_Click(object sender, RoutedEventArgs e)
        {
            // Create message sender sending request messages of type Person and receiving responses of type string.
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();
            myMessageSender = aTypedMessagesFactory.CreateDuplexTypedMessageSender<byte[], byte[]>();
            myMessageSender.ResponseReceived += ResponseReceived;

            // Create messaging based on TCP.
            IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory();
            IDuplexOutputChannel aDuplexOutputChannel = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/");

            // Attach output channel and be able to send messages and receive response messages.
            myMessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);

            myMessageSender.SendRequestMessage(GetBytes(textBox1.Text));
        }