Пример #1
0
        public void DisconnectClient(String remoteIP, String remotePort)
        {
            // Delete Client from Tree View
            UpdateClientList(remoteIP + " : " + remotePort, "Delete");

            // Find Client Chat Dialog box corresponding to this Socket
            int counter = 0;

            foreach (ChatDialog c in formArray)
            {
                String remoteIP1   = ((IPEndPoint)c.connectedClient.Client.RemoteEndPoint).Address.ToString();
                String remotePort1 = ((IPEndPoint)c.connectedClient.Client.RemoteEndPoint).Port.ToString();

                if (remoteIP1.Equals(remoteIP) && remotePort1.Equals(remotePort))
                {
                    break;
                }
                counter++;
            }

            // Terminate Chat Dialog Box
            ChatDialog cd = (ChatDialog)formArray[counter];

            formArray.RemoveAt(counter);

            ((Thread)(threadArray[counter])).Abort();
            threadArray.RemoveAt(counter);
        }
Пример #2
0
        /// <summary>
        /// Event Fired when a Client gets connected. Following actions are performed
        /// 1. Update Tree view
        /// 2. Open a chat box to chat with client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ClientAdded(object sender, EventArgs e)
        {
            tcpClient = ((MyEventArgs)e).clientSock;
            String remoteIP   = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
            String remotePort = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port.ToString();

            // Call Delegate Function to update Tree View
            UpdateClientList(remoteIP + " : " + remotePort, "Add");

            // Show Dialog Box for Chatting
            ctd      = new ChatDialog(this, tcpClient);
            ctd.Text = "Connected to " + remoteIP + "on port number " + remotePort;

            // Add Dialog Box Object to Array List
            formArray.Add(ctd);
            threadArray.Add(Thread.CurrentThread);
            ctd.ShowDialog();
        }