コード例 #1
0
 /// <summary>
 /// 当事件触发时调用
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnIpValidateRequired(IpValidateRequiredEventArgs e)
 {
     if (IpValidateRequired != null)
     {
         IpValidateRequired(this, e);
     }
 }
コード例 #2
0
ファイル: UDPThread.cs プロジェクト: wdearcai/IpMsg.Net
        /// <summary>
        /// 当事件触发时调用
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnIpValidateRequired(IpValidateRequiredEventArgs e)
        {
            if (IpValidateRequired != null)
            {
                IpValidateRequired(this, e);
            }

            IpmEvents.OnUdpIpValidateRequired(_ipmClient, e);
        }
コード例 #3
0
        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
                });
            }
        }
コード例 #4
0
		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;
				}
			}
		}
コード例 #5
0
ファイル: UDPThread.cs プロジェクト: iraychen/IpMsg.Net
		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 });
			}

		}
コード例 #6
0
ファイル: UDPThread.cs プロジェクト: iraychen/IpMsg.Net
		/// <summary>
		/// 当事件触发时调用
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnIpValidateRequired(IpValidateRequiredEventArgs e)
		{
			if (IpValidateRequired != null) IpValidateRequired(this, e);

			IpmEvents.OnUdpIpValidateRequired(_ipmClient, e);
		}
コード例 #7
0
		void MessageClient_IpValidateRequired(object sender, IpValidateRequiredEventArgs e)
		{
			//如果在列表中,则丢弃
			string addr = e.IPEndPoint.Address.ToString();
			if (Config.BanedHost.Contains(addr)) e.IsPackageDroped = true;
		}