예제 #1
0
파일: Station.cs 프로젝트: sontx/dropzone
        private void UpdateNeighborsStatus(object state)
        {
            Ping();

            lock (this)
            {
                var now   = DateTime.Now;
                var pairs = _neighbors.ToArray();
                foreach (var pair in pairs)
                {
                    if (now - pair.Value.LastOnline > Constants.ShortestOnlineTime)
                    {
                        _neighbors.Remove(pair.Key);
                    }
                }

                if (_neighbors.Count != pairs.Length)
                {
                    OnNeighborsChanged?.Invoke();
                }
            }
        }
예제 #2
0
파일: Station.cs 프로젝트: sontx/dropzone
        private void ScanNeighbors()
        {
            while (true)
            {
                var from   = new IPEndPoint(IPAddress.Any, 0);
                var buffer = _client.Receive(ref from);
                var header = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

                Debugger.Log("Received broadcast header: " + header);

                var pingInfo = PingInfo.Parse(header);
                if (pingInfo == null || pingInfo.Id == _id)
                {
                    continue;
                }

                var address  = from.Address.ToString();
                var neighbor = new Neighbor
                {
                    Name       = pingInfo.Name,
                    LastOnline = DateTime.Now,
                    Address    = address
                };

                lock (this)
                {
                    var oldSize = _neighbors.Count;

                    _neighbors[address] = neighbor;

                    if (oldSize != _neighbors.Count)
                    {
                        OnNeighborsChanged?.Invoke();
                    }
                }
            }
        }