Пример #1
0
        private void Run()
        {
            // create a new TcpListener and start it up
            // listening on port 65000

            IPAddress   localAddr   = IPAddress.Parse("127.0.0.1");
            TcpListener tcpListener = new TcpListener(localAddr, 65000);

            tcpListener.Start();

            // keep listening until you send the file
            for ( ; ;)
            {
                // if a client connects, accept the connection
                // and return a new socket named socketForClient
                // while tcpListener keeps listening
                Socket socketForClient =
                    tcpListener.AcceptSocket();
                Console.WriteLine("Client connected");
                ClientHandler handler =
                    new ClientHandler(socketForClient);
                handler.StartRead();
            }
        }