Esempio n. 1
0
        void Send(Message msg, bool checkDuplicate, IPEndPoint remoteEndPoint = null, bool isLegacyUnicast = false)
        {
            var packet = msg.ToByteArray();

            if (packet.Length > maxPacketSize)
            {
                throw new ArgumentOutOfRangeException($"Exceeds max packet size of {maxPacketSize}.");
            }

            if (checkDuplicate && !sentMessages.TryAdd(packet))
            {
                return;
            }

            // Standard multicast response?
            if (remoteEndPoint == null && !isLegacyUnicast)
            {
                // no clear remote endpoint or querier defined - could be from an announce
                // better perform asynchronously, because this message gets sent on all available NICs and should not block
                Task.Run(() => client?.SendAsync(msg).GetAwaiter().GetResult()).ConfigureAwait(false);
            }
            else if (!isLegacyUnicast)
            {
                client?.SendAsync(msg, remoteEndPoint.Address).GetAwaiter().GetResult();
            }

            // Unicast response
            if (isLegacyUnicast && remoteEndPoint != null)
            {
                var unicastClient = (remoteEndPoint.Address.AddressFamily == AddressFamily.InterNetwork)
                    ? unicastClientIp4 : unicastClientIp6;
                unicastClient.SendAsync(packet, packet.Length, remoteEndPoint).GetAwaiter().GetResult();
            }
        }
Esempio n. 2
0
        void Send(Message msg, bool checkDuplicate, IPEndPoint remoteEndPoint = null)
        {
            var packet = msg.ToByteArray();

            if (packet.Length > maxPacketSize)
            {
                throw new ArgumentOutOfRangeException($"Exceeds max packet size of {maxPacketSize}.");
            }

            if (checkDuplicate && !sentMessages.TryAdd(packet))
            {
                return;
            }

            // Standard multicast reponse?
            if (remoteEndPoint == null)
            {
                client?.SendAsync(packet).GetAwaiter().GetResult();
            }
            // Unicast response
            else
            {
                var unicastClient = (remoteEndPoint.Address.AddressFamily == AddressFamily.InterNetwork)
                    ? unicastClientIp4 : unicastClientIp6;
                unicastClient.SendAsync(packet, packet.Length, remoteEndPoint).GetAwaiter().GetResult();
            }
        }
Esempio n. 3
0
        void Send(Message msg, bool checkDuplicate)
        {
            var packet = msg.ToByteArray();

            if (packet.Length > maxPacketSize)
            {
                throw new ArgumentOutOfRangeException($"Exceeds max packet size of {maxPacketSize}.");
            }

            if (checkDuplicate && !sentMessages.TryAdd(packet))
            {
                return;
            }

            client.SendAsync(packet).GetAwaiter().GetResult();
        }