/// <summary> /// Constructs New AsyncListener /// </summary> /// <param name="ip">IP On Which We Will Wait For Connections</param> /// <param name="port">Port On Which We Will Wait For Connections</param> /// <param name="defined">Defined Connection Type Instance Of What We Will Create When Accept Any Connection.</param> public AsyncListenerUDP(string ip, int port, Type defined) { this.defined = defined; IPEndPoint point = new IPEndPoint(IPAddress.Parse(ip), port); this.m_EndPoint = point; try { Socket s = new Socket(point.AddressFamily, SocketType.Dgram, ProtocolType.Udp); //s.LingerState.Enabled = false; /*#if !MONO * s.ExclusiveAddressUse = false; #endif*/ s.Bind(point); IConnectionUDP con = Activator.CreateInstance(this.defined, s) as IConnectionUDP; this.m_Root = s; } catch (SocketException e) { Log.Info(e.ToString()); } Log.Info("Installed {0} at {1}", defined.Name, point); this.m_SyncArgs = new SocketAsyncEventArgs(); //this.m_SyncArgs.Completed += this.M_SyncArgs_Completed; // this.RunAccept(); //his.m_FloodAttempts = new Dictionary<string, long>(); }
/// <summary> /// Calls When Accept Done and We need create a Connection. /// Also Have Flood Control. /// </summary> /// <param name="e">Event Arguments That Contains Accepted Socket.</param> private void AcceptProceed(SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success) { IConnectionUDP con = Activator.CreateInstance(this.defined, e.AcceptSocket) as IConnectionUDP; //Main.Set(); } e.AcceptSocket = null; }