Example #1
0
        private void AcceptConnections()
        {
            while (!started)
            {
                TcpClient client = null;

                try
                {
                    client = server.AcceptTcpClient();
                    ConnectedComputer newClient = new ConnectedComputer(-1, client, null);

                    StreamReader rdr = new StreamReader(client.GetStream());
                    newClient.Number = Convert.ToInt32(rdr.ReadLine());

                    if (newClient.Number <= 0)
                    {
                        throw new Exception("Number can't be less or equal to zero");
                    }

                    if (clientList.Find(c => c.IP == newClient.IP) != null)
                    {
                        continue;
                    }

                    clientList.Add(newClient);
                    Invoke(new Action(() => lbConnected.Items.Add("#" + newClient.Number + " - " + Dns.GetHostEntry(newClient.IP).HostName)));
                }
                catch
                {
                    if (client != null)
                    {
                        client.Close();
                    }
                }
            }
        }
Example #2
0
 private int ClientCompare(ConnectedComputer c1, ConnectedComputer c2)
 {
     return(c1.Number.CompareTo(c2.Number));
 }