예제 #1
0
        /// <summary>
        /// Callback which is called when UDP packet is received
        /// </summary>
        /// <param name="ar">Received data</param>
        private void ReceivedCallback(IAsyncResult ar)
        {
            // Get received data
            IPEndPoint sender = new IPEndPoint(0, 0);

            Byte[] receivedBytes = _udpclient.EndReceive(ar, ref sender);

            // fire event if defined
            UdpMessageReceived?.Invoke(this, new UdpMessageReceivedEventArgs()
            {
                Buffer = receivedBytes
            });

            // Restart listening for udp data packages
            _udpclient.BeginReceive(new AsyncCallback(ReceivedCallback), null);
        }
 /// <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);
 }