/// <summary>
		/// Contains information about the location of a device on the network.
		/// </summary>
		/// <param name="Client">UPnP Client</param>
		/// <param name="Headers">All headers in notification.</param>
		/// <param name="LocalEndPoint">Local End Point.</param>
		/// <param name="RemoteEndPoint">Remote End Point.</param>
		internal NotificationEventArgs(UPnPClient Client, UPnPHeaders Headers, IPEndPoint LocalEndPoint, IPEndPoint RemoteEndPoint)
		{
			this.client = Client;
			this.headers = Headers;
			this.localEndPoint = LocalEndPoint;
			this.remoteEndPoint = RemoteEndPoint;
		}
예제 #2
0
		/// <summary>
		/// Contains information about the location of a device on the network.
		/// </summary>
		/// <param name="SearchTarget">SSDP Search Target</param>
		/// <param name="Server">Server</param>
		/// <param name="Location">Location of device information</param>
		/// <param name="UniqueServiceName">Unique Service Name (USN)</param>
		/// <param name="Headers">All headers in response.</param>
		internal DeviceLocation(UPnPClient Client, string SearchTarget, string Server, string Location, string UniqueServiceName, UPnPHeaders Headers)
		{
			this.client = Client;
			this.searchTarget = SearchTarget;
			this.server = Server;
			this.location = Location;
			this.uniqueServiceName = UniqueServiceName;
			this.headers = Headers;
		}
예제 #3
0
		private void EndReceiveIncoming(IAsyncResult ar)
		{
			try
			{
				UdpClient UdpClient = (UdpClient)ar.AsyncState;
				IPEndPoint RemoteIP = null;
				byte[] Packet = UdpClient.EndReceive(ar, ref RemoteIP);
				string Header = Encoding.ASCII.GetString(Packet);
				UPnPHeaders Headers = new UPnPHeaders(Header);

				if (RemoteIP != null && Headers.Direction == HttpDirection.Request && Headers.HttpVersion >= 1.0)
					this.HandleIncoming(UdpClient, RemoteIP, Headers);

				UdpClient.BeginReceive(this.EndReceiveOutgoing, UdpClient);
			}
			catch (Exception ex)
			{
				this.RaiseOnError(ex);
			}
		}
예제 #4
0
		private void HandleIncoming(UdpClient UdpClient, IPEndPoint RemoteIP, UPnPHeaders Headers)
		{
			switch (Headers.Verb)
			{
				case "M-SEARCH":
					NotificationEventHandler h = this.OnSearch;
					if (h != null)
					{
						try
						{
							h(this, new NotificationEventArgs(this, Headers, (IPEndPoint)UdpClient.Client.LocalEndPoint, RemoteIP));
						}
						catch (Exception ex)
						{
							this.RaiseOnError(ex);
						}
					}
					break;

				case "NOTIFY":
					h = this.OnNotification;
					if (h != null)
					{
						try
						{
							h(this, new NotificationEventArgs(this, Headers, (IPEndPoint)UdpClient.Client.LocalEndPoint, RemoteIP));
						}
						catch (Exception ex)
						{
							this.RaiseOnError(ex);
						}
					}
					break;
			}
		}
예제 #5
0
		private void EndReceiveOutgoing(IAsyncResult ar)
		{
			try
			{
				UdpClient UdpClient = (UdpClient)ar.AsyncState;
				IPEndPoint RemoteIP = null;
				byte[] Packet = UdpClient.EndReceive(ar, ref RemoteIP);
				string Header = Encoding.ASCII.GetString(Packet);
				UPnPHeaders Headers = new UPnPHeaders(Header);

				if (RemoteIP != null && Headers.Direction == HttpDirection.Response && Headers.HttpVersion >= 1.0 && Headers.ResponseCode == 200)
				{
					if (!string.IsNullOrEmpty(Headers.Location))
					{
						UPnPDeviceLocationEventHandler h = this.OnDeviceFound;
						if (h != null)
						{
							DeviceLocation DeviceLocation = new DeviceLocation(this, Headers.SearchTarget, Headers.Server, Headers.Location,
								Headers.UniqueServiceName, Headers);
							DeviceLocationEventArgs e = new DeviceLocationEventArgs(DeviceLocation, (IPEndPoint)UdpClient.Client.LocalEndPoint, RemoteIP);
							try
							{
								h(this, e);
							}
							catch (Exception ex)
							{
								this.RaiseOnError(ex);
							}
						}
					}
				}
				else if (Headers.Direction == HttpDirection.Request && Headers.HttpVersion >= 1.0)
					this.HandleIncoming(UdpClient, RemoteIP, Headers);

				UdpClient.BeginReceive(this.EndReceiveOutgoing, UdpClient);
			}
			catch (Exception ex)
			{
				this.RaiseOnError(ex);
			}
		}