/// <summary> /// 当事件触发时调用 /// </summary> /// <param name="e"></param> protected virtual void OnIpValidateRequired(IpValidateRequiredEventArgs e) { if (IpValidateRequired != null) { IpValidateRequired(this, e); } }
/// <summary> /// 当事件触发时调用 /// </summary> /// <param name="e"></param> protected virtual void OnIpValidateRequired(IpValidateRequiredEventArgs e) { if (IpValidateRequired != null) { IpValidateRequired(this, e); } IpmEvents.OnUdpIpValidateRequired(_ipmClient, e); }
void EndReceiveDataAsync(IAsyncResult ar) { IPEndPoint ipend = null; byte[] buffer = null; try { buffer = client.EndReceive(ar, ref ipend); } catch (Exception) { return; } finally { if (IsInitialized && client != null) { client.BeginReceive(EndReceiveDataAsync, null); } } if (buffer == null || buffer.Length == 0) { return; } //验证IP IpValidateRequiredEventArgs ev = new IpValidateRequiredEventArgs() { IPEndPoint = ipend, Data = buffer }; OnIpValidateRequired(ev); //消息被过滤时,直接返回 if (ev.IsPackageDroped) { NetworkPackageEventArgs pea = new NetworkPackageEventArgs() { IPEndPoint = ipend }; OnPackageDroped(pea); } else { OnPackageReceived(new PackageReceivedEventArgs() { RemoteIP = ipend, Data = buffer }); } }
void MessageClient_IpValidateRequired(object sender, IpValidateRequiredEventArgs e) { //检测事件 if (e.IsPackageDroped) return; foreach (var ip in Client.LocalAddresses) { if (ip.IsSameIPAs(e.IPEndPoint.Address)) { e.IsPackageDroped = true; break; } } }
void EndReceiveDataAsync(IAsyncResult ar) { IPEndPoint ipend = null; byte[] buffer = null; try { buffer = client.EndReceive(ar, ref ipend); } catch (Exception) { return; } finally { if (IsInitialized && client != null) client.BeginReceive(EndReceiveDataAsync, null); } if (buffer == null || buffer.Length == 0) return; //验证IP IpValidateRequiredEventArgs ev = new IpValidateRequiredEventArgs() { IPEndPoint = ipend, Data = buffer }; OnIpValidateRequired(ev); //消息被过滤时,直接返回 if (ev.IsPackageDroped) { NetworkPackageEventArgs pea = new NetworkPackageEventArgs() { IPEndPoint = ipend }; OnPackageDroped(pea); } else { OnPackageReceived(new PackageReceivedEventArgs() { RemoteIP = ipend, Data = buffer }); } }
/// <summary> /// 当事件触发时调用 /// </summary> /// <param name="e"></param> protected virtual void OnIpValidateRequired(IpValidateRequiredEventArgs e) { if (IpValidateRequired != null) IpValidateRequired(this, e); IpmEvents.OnUdpIpValidateRequired(_ipmClient, e); }
void MessageClient_IpValidateRequired(object sender, IpValidateRequiredEventArgs e) { //如果在列表中,则丢弃 string addr = e.IPEndPoint.Address.ToString(); if (Config.BanedHost.Contains(addr)) e.IsPackageDroped = true; }