/// <summary> /// Waits for UDP broadcasts to arrive. /// </summary> /// <returns>This function doesn't return. However the <see cref="UdpMessageReceived"/> event is fired when a message is received.</returns> public async Task ReceiveAsync() { while (!cancel) { try { var result = await client.ReceiveAsync(); var content = Encoding.UTF8.GetString(result.Buffer); try { var args = new UdpMessageReceivedEventArgs(result.RemoteEndPoint, content); OnUdpMessageReceived(this, args); } catch { } } catch { } } }
/// <summary> /// Raises the <see cref="UdpMessageReceived"/> event. /// </summary> /// <param name="sender">The <see cref="UdpReceiver"/> that received the message.</param> /// <param name="e">An <see cref="EventArgs"/> that contains information about the received message.</param> protected virtual void OnUdpMessageReceived(UdpReceiver sender, UdpMessageReceivedEventArgs e) { UdpMessageReceived?.Invoke(sender, e); }