/// <summary>
/// This method will constantly run as a thread. It currently sends a multicast to the network every second, informing
/// computers on the network that it is there. When a client sees this, it will send a message to the server and the client
/// will be added to the clients list.
/// </summary>
public static void AddClients()
{
clients = new List<ClientThread>();
TcpListener serverSocket = new TcpListener(IPAddress.Any, 8888);
serverSocket.Start();
while (true)
{
TcpClient tempClientSocket = new TcpClient();
tempClientSocket.ReceiveTimeout = 300;
SendMulticast();
//Check and see if a computer is trying to connect.
//If not, then sleep, and resend multicast in a second
if (serverSocket.Pending())
{
tempClientSocket = serverSocket.AcceptTcpClient();
ClientThread c = new ClientThread(tempClientSocket,null);
clients.Add(c);
Console.WriteLine("Connected to " + c.GetClientIP() + " :: "+c.GetPort());
}
else {
Thread.Sleep(1000); //Sleep for a second, before sending the next multicast.
}
}
}