BACnet.IP.ForeignDevicePort._onDatagramReceived C# (CSharp) Méthode

_onDatagramReceived() private méthode

Called whenever a datagram is received
private _onDatagramReceived ( IPEndPoint ep, byte buffer, int length ) : void
ep System.Net.IPEndPoint The IPEndPoint of the sending device
buffer byte The buffer containing the datagram
length int The length of the received datagram
Résultat void
        private void _onDatagramReceived(IPEndPoint ep, byte[] buffer, int length)
        {
            int offset = 0;
            BvlcHeader header = null;
            IBvlcMessage message = null;
            NetgramReceivedMessage netgram = null;
            Mac mac = IPUtils.IPEndPointToMac(ep);

            try
            {
                if (length < 4)
                    throw new Exception("Received datagram under 4 bytes long");

                header = new BvlcHeader();
                offset = header.Deserialize(buffer, offset);

                if (header.Length != length)
                    throw new Exception("Received bvlc datagram with non-matching lengths");

                message = _createMessage(header.Function);
                offset = message.Deserialize(buffer, offset);
                lock (_lock)
                {
                    netgram = _processMessage(mac, message, buffer, offset, length);
                }

                if (netgram != null && Session != null)
                    Session.QueueMessage(netgram);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }