public RedistLocalConnectionTableRegistrator(int port, TimeSpan sendDelay) { _client = new UdpClient(); var ep = new IPEndPoint(IPAddress.Broadcast, port); _timer = new AsyncLoopTimer(sendDelay, () => { foreach (var bytes in _registedConnections) { _client.Send(bytes, bytes.Length, ep); } }); }
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); } }); }