private async void DownloadThread(object state) { var socket = new AresUdpSocket(new ChannelFormatter()); socket.PacketReceived += UdpPacketReceived; socket.ReceiveAsync(); int i = 0; while (IsDownloading) { DateTime now = DateTime.Now; Channels .Skip(i) .Take(10) .ForEach(s => { s.LastSendInfo = now; socket.SendAsync( new SendInfo(), new IPEndPoint(s.ExternalIp, s.Port)); }); i = Math.Min(Channels.Count, i + 10); await CheckDownloadTimeout(socket); } }
private void SocketException(object sender, ExceptionEventArgs e) { if (socket != null) { socket.ReceiveAsync(); } }
void StartSocket(int port) { socket = new AresUdpSocket(new ChannelFormatter()); socket.PacketReceived += UdpPacketReceived; socket.Bind(new IPEndPoint(IPAddress.Any, port)); udptimer.Change(TimeSpan.Zero, ticklength); IsRunning = true; socket.ReceiveAsync(); }
void StartSocket() { socket = new AresUdpSocket(new ChannelFormatter()); socket.Exception += SocketException; socket.PacketReceived += PacketReceived; socket.Bind(new IPEndPoint(IPAddress.Any, server.Config.Port)); timer.Change(TimeSpan.Zero, ticklength); socket.ReceiveAsync(); }