Пример #1
0
        public void CloseClient(Client client)
        {
            lock(_sync)
            _clients.Remove(client);

             client.Dispose();
        }
Пример #2
0
        void AcceptCallback(IAsyncResult result)
        {
            var listener = (TcpListener)result.AsyncState;

             try
             {
            var socket = listener.EndAcceptSocket(result);
            var client = new Client(this, socket, MaxPackageLength, Dispatcher);

            lock(_sync)
               _clients.Add(client);

            listener.BeginAcceptSocket(AcceptCallback, listener);
            socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, ReceiveCallback, client);
             }
             catch(SocketException ex)
             {
            Console.WriteLine("Accept error: {0}", ex);
             }
             catch(ObjectDisposedException)
             {
             }
        }