private async void BeginReceiveOutgoing(UdpClient Client) { try { while (!this.disposed) { UdpReceiveResult Data = await Client.ReceiveAsync(); if (this.disposed) { return; } byte[] Packet = Data.Buffer; this.ReceiveBinary(Packet); try { string Header = Encoding.ASCII.GetString(Packet); UPnPHeaders Headers = new UPnPHeaders(Header); this.ReceiveText(Header); if (Headers.Direction == HttpDirection.Response && Headers.HttpVersion >= 1.0 && Headers.ResponseCode == 200) { if (!string.IsNullOrEmpty(Headers.Location)) { UPnPDeviceLocationEventHandler h = this.OnDeviceFound; if (!(h is null)) { DeviceLocation DeviceLocation = new DeviceLocation(this, Headers.SearchTarget, Headers.Server, Headers.Location, Headers.UniqueServiceName, Headers); DeviceLocationEventArgs e = new DeviceLocationEventArgs(DeviceLocation, (IPEndPoint)Client.Client.LocalEndPoint, Data.RemoteEndPoint); try { h(this, e); } catch (Exception ex) { this.RaiseOnError(ex); } } } } else if (Headers.Direction == HttpDirection.Request && Headers.HttpVersion >= 1.0) { this.HandleIncoming(Client, Data.RemoteEndPoint, Headers); } } catch (Exception ex) { this.RaiseOnError(ex); } } } catch (ObjectDisposedException) { // Closed. } catch (Exception ex) { this.Exception(ex); } }
internal DeviceLocationEventArgs(DeviceLocation Location, IPEndPoint LocalEndPoint, IPEndPoint RemoteEndPoint) { this.location = Location; this.localEndPoint = LocalEndPoint; this.remoteEndPoint = RemoteEndPoint; }