/// <summary> /// This is called whenever the listener has received a connection. /// </summary> /// <param name="iResult">The AsyncResult.</param> public virtual void OnIncomingConnection(IAsyncResult iResult) { // Do this check if (!_shutdown && iResult.IsCompleted) { // Handle the connection var client = _listener.EndAcceptTcpClient(iResult); // create the new client var pClient = new Client.Client(client); lock (_clients) { // add the client _clients.Add(pClient); } // attach event handlers pClient.DataReceived += PClientOnDataReceived; pClient.Disconnected += PClientOnDisconnected; pClient.Exception += PClientOnException; // Raise an Event ClientConnected(this, new PhoenixServerClientConnectedEventArgs { Client = pClient }); // Begin reading pClient.BeginRead(); // We have the client, go back to listening _listener.BeginAcceptTcpClient(OnIncomingConnection, null); } }