Пример #1
0
        private void HandleClientConnectedChanged(object sender, PropertyEventArgs args)
        {
            TCPClient client = (TCPClient)sender;

            if (args is PropertyChangeEventArgs)
            {
                if ((bool)((PropertyChangeEventArgs)args).NewValue == true)
                {
                    using (Synchronizer.Lock(this.SyncRoot))
                        this.SetPublishedProperty("ClientConnected", ref m_ClientConnected, true);
                    if (m_Sender == null)
                    {
                        m_Sender = new TCPMessageSender(client, this.m_Model, this.m_Classroom);
                        Trace.WriteLine("Client Connection Handler Started TCPMessageSender.", this.GetType().ToString());
                    }
                }
                else
                {
                    using (Synchronizer.Lock(this.SyncRoot))
                        this.SetPublishedProperty("ClientConnected", ref m_ClientConnected, false);
                }
            }
        }
        private void StartClient()
        {
            if (m_Client != null) {
                Trace.WriteLine("Attempt to start a TCPClient when a client is already running.", this.GetType().ToString());
                return;

                //throw (new ApplicationException("Attempt to start a TCPClient when a client is already running."));
            }
            m_Client = new TCPClient(m_InstructorAdvertisement.Endpoint, this.m_Model.Participant, this.m_Model.Network, m_InstructorAdvertisement.InstructorID);
            m_Client.Changed["Connected"].Add(new PropertyEventHandler(HandleClientConnectedChanged)); //Start sender only after we are connected.
            m_Client.Start();
            m_Receiver = new TCPMessageReceiver(m_Client, this.m_Model, this.m_Classroom);
        }