private void ResponseReceived(IAsyncResult ar)
        {
            _log.Information("Incomming Reponse");
            var remote = new IPEndPoint(IPAddress.Any, 0);
            var bytes  = _udp.EndReceive(ar, ref remote);

            var typeBytes = Beacon.Encode(BeaconType);

            if (Beacon.HasPrefix(bytes, typeBytes))
            {
                try
                {
                    _log.Information("Processing Response");
                    var portBytes = bytes.Skip(typeBytes.Length).Take(2).ToArray();
                    var port      = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(portBytes, 0));
                    var payload   = Beacon.Decode(bytes.Skip(typeBytes.Length + 2));
                    NewBeacon(new BeaconLocation(new IPEndPoint(remote.Address, port), payload, DateTime.Now));
                }
                catch (Exception ex)
                {
                    _log.Error(ex, "Error on Decode Recived Beacon");
                }
            }
            else
            {
                _log.Information("Incompatiple Data");
            }

            _udp.BeginReceive(ResponseReceived, null);
        }
Exemplo n.º 2
0
        private void ResponseReceived(IAsyncResult ar)
        {
            var remote = new IPEndPoint(IPAddress.Any, 0);
            var bytes  = udp.EndReceive(ar, ref remote);

            var typeBytes = Beacon.Encode(BeaconType).ToList();

            Debug.WriteLine(string.Join(", ", typeBytes.Select(_ => (char)_)));
            if (Beacon.HasPrefix(bytes, typeBytes))
            {
                try
                {
                    var portBytes = bytes.Skip(typeBytes.Count()).Take(2).ToArray();
                    var port      = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(portBytes, 0));
                    var payload   = Beacon.Decode(bytes.Skip(typeBytes.Count() + 2));
                    NewBeacon(new BeaconLocation(new IPEndPoint(remote.Address, port), payload, DateTime.Now));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            udp.BeginReceive(ResponseReceived, null);
        }
        private void BroadcastProbe()
        {
            _log.Information("Sending Request");
            var probe = Beacon.Encode(BeaconType).ToArray();

            _udp.Send(probe, probe.Length, new IPEndPoint(IPAddress.Broadcast, Beacon.DiscoveryPort));
        }
Exemplo n.º 4
0
        private void BroadcastProbe()
        {
            //UnityEngine.Debug.Log("Sending BroadcastProbe");
            var probe = Beacon.Encode(BeaconType).ToArray();

            udp.Send(probe, probe.Length, new IPEndPoint(IPAddress.Broadcast, Beacon.DiscoveryPort));
        }
Exemplo n.º 5
0
        private void ResponseReceived(IAsyncResult ar)
        {
            if (ar.AsyncState == null)
            {
                throw new InvalidOperationException("The ResponseReceived callback should have contained a UdpClient in AsyncState but it was null.");
            }

            var udp = (UdpClient)ar.AsyncState;

            var remote = new IPEndPoint(IPAddress.Any, 0);
            var bytes  = udp.EndReceive(ar, ref remote);

            var typeBytes = Beacon.Encode(BeaconType).ToList();

            Debug.WriteLine(string.Join(", ", typeBytes.Select(_ => (char)_)));
            if (Beacon.HasPrefix(bytes, typeBytes))
            {
                try
                {
                    var portBytes = bytes.Skip(typeBytes.Count).Take(2).ToArray();
                    var port      = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(portBytes, 0));
                    var payload   = Beacon.Decode(bytes.Skip(typeBytes.Count + 2));
                    NewBeacon(new BeaconLocation(new IPEndPoint(remote.Address, port), payload, DateTime.Now));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }

            udp.BeginReceive(ResponseReceived, udp);
        }
Exemplo n.º 6
0
        private void BroadcastProbe()
        {
            var probe = Beacon.Encode(BeaconType).ToArray();

            foreach (var udp in _clients)
            {
                udp.Send(probe, probe.Length, new IPEndPoint(IPAddress.Broadcast, _discoveryPort));
            }
        }
Exemplo n.º 7
0
        private void BroadcastProbe()
        {
            var probe = Beacon.Encode(BeaconType).ToArray();

            udp.Send(probe, probe.Length, new IPEndPoint(IPAddress.Broadcast, Beacon.DiscoveryPort));
        }