Beispiel #1
0
        static void Main(string[] args)
        {
            // Setting up and starting the server
            IPAddress serverIP = IPAddress.Parse(IP);
            TcpListener server = new TcpListener(serverIP, PORT);
            server.Start();

            // Setting up and
            Timer clientReportTimer = new Timer(clientReport);
            clientReportTimer.Change(0, 1000);

            // Waiting for new connections
            while (true)
            {

                Console.WriteLine("Waiting for connection");

                // If there is a new connection we accept it
                // and increase the clientId variable
                TcpClient client = server.AcceptTcpClient();
                MyClient.clientId++;

                Console.WriteLine("Client Connection Request Accepted");

                // We create a new instance of MyClient, which manages communication
                MyClient tempClient = new MyClient();

                tempClient.id = MyClient.clientId;

                tempClient.client = client;
                tempClient.ip = ((IPEndPoint)client.Client.RemoteEndPoint).Address;

                // Creating a new thread for the client
                Thread thread = new Thread(new ParameterizedThreadStart(tempClient.clientHandler));
                tempClient.thread = thread;

                // adding the client to the List
                clients.Add(tempClient);

                thread.Start(tempClient);

            }
        }
Beispiel #2
0
 // Removing the client from the clients List
 public static void removeClient(MyClient client)
 {
     clients.Remove(client);
 }