public void CloseClient(Client client) { lock(_sync) _clients.Remove(client); client.Dispose(); }
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) { } }