public void OnAcceptTcpClient(IAsyncResult ar) { try { Socket socket = _listener.EndAcceptSocket(ar); Client cli = new Client(socket); if (OnConnect != null) { OnConnect(cli); } } catch (Exception) { } try { _listener.BeginAcceptTcpClient(new AsyncCallback(OnAcceptTcpClient), null); } catch (Exception) { _isListening = false; } }
void client_OnDisconnect(Client client) { Statistics.RemoveConnectedClient(); lock (_cleanupPool) { lock (_cleanupPool) { if (_cleanupPool.ContainsKey(client.UniqueId)) _cleanupPool.Remove(client.UniqueId); } } }
void client_OnPolicyRequest(Client client) { Statistics.CountRequest(); byte[] buf = Encoding.ASCII.GetBytes("<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>\0"); try { client.Send(buf, 0, buf.Length); } catch (Exception) { try { client.Stop(); } catch (Exception) { } } }
void _listener_OnConnect(Client client) { client.OnPolicyRequest += new Client.OnPolicyRequestDelegate(client_OnPolicyRequest); client.OnDisconnect += new Client.OnDisconnectDelegate(client_OnDisconnect); client.Start(); Statistics.AddConnectedClient(); lock (_cleanupPool) { _cleanupPool.Add(client.UniqueId, new CleanupEntry() { Client = client, TimeOfInsertion = DateTime.Now }); } }