Example #1
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 });
			}

		}
Example #2
0
		/// <summary>
		/// 主机消息包被丢弃时,被调用
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnPackageDroped(NetworkPackageEventArgs e)
		{
			if (PackageDroped != null) PackageDroped(this, e);

			IpmEvents.OnUdpPackageDroped(_ipmClient, e);
		}