Ejemplo n.º 1
0
 private void InitializeListener(UdpConnectionOption option)
 {
     _listener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
     _listener.ExclusiveAddressUse = false;
     _connection = new IPEndPoint(option.Address, option.Port);
     _listener.Client.Bind(_connection);
     _listener.BeginReceive(AsyncHandle, _listener);
 }
Ejemplo n.º 2
0
        public RedistLocalConnectionTable(UdpConnectionOption options, RedistributableTableOption tableOption)
        {
            OnConnected    += delegate { };
            OnDisconnected += delegate { };
            InitializeListener(options);
            _registrator = new RedistLocalConnectionTableRegistrator(options.Port, tableOption.NotifyTime);
            _timer       = new AsyncLoopTimer(tableOption.LoopTime, () =>
            {
                foreach (var value in _table)
                {
                    if (DateTime.UtcNow.TimeOfDay.Subtract(value.Value.TimeStamp) <= tableOption.ExpirationTime)
                    {
                        continue;
                    }

                    _table.TryRemove(value.Key, out var info);
                    var args = new ConnectionArgs(info.Data);
                    OnDisconnected?.Invoke(this, args);
                }
            });
        }