예제 #1
0
        ///<summary>
        /// starts an endless loop which accepts new clients
        ///</summary>
        protected override void ListenForClients()
        {
            base.ListenForClients();

            while (this.Status != ServerStatus.STOPPED)
            {
                /* blocks until a client has connected to the server and another client is allowed
                 * MaximalAllowedClients means no limit                                             */
                if (this.MaximalAllowedClients == 0 || this.clients.Count < this.MaximalAllowedClients)
                {
                    // Initialize a new TCPCLient if an client wants to connect
                    TcpClient tcpClient = this.tcpListener.AcceptTcpClient();

                    TCPServer_StreamBasedClient_EventArgs_ClientConnect tcpServer_StreamBasedClient_EventArgs_Connect = new TCPServer_StreamBasedClient_EventArgs_ClientConnect(tcpClient);
                    this.ClientConnect(this, tcpServer_StreamBasedClient_EventArgs_Connect);

                    // Add this new tcpClient to the clients list which includes each connected client
                    this.clients.Add(tcpClient);

                    /* create a thread to handle communication
                     * with connected client                   */
                    Thread clientThread = new Thread(new ParameterizedThreadStart(this.HandleClientCommunication));

                    this.clientThreads.Add(clientThread);
                    this.clientThreads[this.clientThreads.IndexOf(clientThread)].Start(tcpClient);
                }
            }
        }
예제 #2
0
        ///<summary>
        /// starts an endless loop which accepts new clients
        ///</summary>
        protected override void ListenForClients()
        {
            base.ListenForClients();

            while(this.Status != ServerStatus.STOPPED)
            {

                /* blocks until a client has connected to the server and another client is allowed
                   MaximalAllowedClients means no limit                                             */
                if (this.MaximalAllowedClients == 0 || this.clients.Count < this.MaximalAllowedClients)
                {

                    // Initialize a new TCPCLient if an client wants to connect
                    TcpClient tcpClient = this.tcpListener.AcceptTcpClient();

                    TCPServer_StreamBasedClient_EventArgs_ClientConnect tcpServer_StreamBasedClient_EventArgs_Connect = new TCPServer_StreamBasedClient_EventArgs_ClientConnect(tcpClient);
                    this.ClientConnect(this, tcpServer_StreamBasedClient_EventArgs_Connect);

                    // Add this new tcpClient to the clients list which includes each connected client
                    this.clients.Add(tcpClient);

                    /* create a thread to handle communication
                     * with connected client                   */
                    Thread clientThread = new Thread(new ParameterizedThreadStart(this.HandleClientCommunication));

                    this.clientThreads.Add(clientThread);
                    this.clientThreads[this.clientThreads.IndexOf(clientThread)].Start(tcpClient);
                }

            }
        }