public ClientDetails(String _ClientID, TcpClient _clientSocket)
 {
     ClientID = _ClientID;
     clientSocket = _clientSocket;
     messages = new List<MessageContainer>();
     ClientName = "";
     userName = ClientID.Split(':')[0];
     password = ClientID.Split(':')[1];
     label = new Label();
     label.AutoSize = true;
     label.BorderStyle = BorderStyle.FixedSingle;
     label.Width = 216;
     label.MinimumSize = new System.Drawing.Size(205, 20);
     label.Margin = new Padding(0, 0, 0, 5);
     label.Click += label_Click;
     label.MouseEnter += label_MouseEnter;
     label.MouseLeave += label_MouseLeave;
     clientView = null;
     server = null;
 }
        public void listen()
        {
            String host = Dns.GetHostName();
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
            String ServerIP = "";
            foreach (IPAddress local in localIPs)
            {
                if (local.AddressFamily == AddressFamily.InterNetwork)
                {
                    if (local.ToString().IndexOf("192.168.") != -1)
                    {
                        displayInMainForm("Server IP: " + local.ToString());
                        ServerIP = local.ToString();
                    }
                }
            }

            IPAddress localAddr = IPAddress.Parse("127.0.0.1");
            serverSocket = new TcpListener(IPAddress.Any,Convert.ToInt32(AmaranthineServer.Properties.Settings.Default.Port));

            clientSocket = default(TcpClient);
            displayInMainForm("Listening Started");

            serverSocket.Start();
            displayInMainForm("Accepting connections from client");

            List<Thread> listOfServers = new List<Thread>();
            Sentinel sentinel = new Sentinel(this);
            Thread sentinelThread = new Thread(new ThreadStart(sentinel.monitorClients));
            sentinelThread.Start();
            while (frm_Main.exitcode != "exit")
            {
                try
                {
                    clientSocket = serverSocket.AcceptTcpClient();

                    Server newServerObj = new Server(frm_Main, clientSocket, listOfClients,this);
                    Thread newServer = new Thread(new ThreadStart(newServerObj.main));
                    listOfServers.Add(newServer);
                    newServer.Start();
                }
                catch (Exception)
                { }
            }

            try
            {
                if (sentinelThread.IsAlive)
                    sentinelThread.Abort();
                clientSocket.Close();
                serverSocket.Stop();

                foreach (ClientDetails client in listOfClients)
                {
                    try
                    {
                        client.clientSocket.Close();
                    }
                    catch (Exception)
                    { }
                }
                listOfClients.Clear();
                foreach (Thread obj in listOfServers)
                    obj.Abort();
            }
            catch (Exception)
            { }

            displayInMainForm("Listening Stopped");
        }