Beispiel #1
0
        private async Task SendMessage(string msg)
        {
            await _log.DebugAsync($"Aria2: Write Message: {msg}");

            _messageWriter.WriteString(msg);
            try
            {
                await _messageWriter.StoreAsync();

                await _messageWriter.FlushAsync();

                await _log.DebugAsync($"Aria2: Message send: {msg}");
            }
            catch (Exception ex)
            {
                await _log.ErrorAsync("Fehler beim Speichern des Json-Objects", ex);
            }
        }
Beispiel #2
0
        private static async Task WakeOnLan()
        {
            byte[] mac = ResourceLoader.GetForViewIndependentUse("Config").GetString("NetworkHelper_HostMacAddress").Split(':').Select(x => Convert.ToByte(x, 16)).ToArray();
            // WOL packet contains a 6-bytes trailer and 16 times a 6-bytes sequence containing the MAC address.
            byte[] packet = new byte[17 * 6];
            // Trailer of 6 times 0xFF.
            for (int i = 0; i < 6; i++)
            {
                packet[i] = 0xFF;
            }
            // Body of magic packet contains 16 times the MAC address.
            for (int i = 1; i <= 16; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    packet[i * 6 + j] = mac[j];
                }
            }
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Broadcast, 40000);

            try
            {
                // WOL packet is sent over UDP 255.255.255.0:40000.
                using (UdpClient client = new UdpClient())
                {
                    client.EnableBroadcast = true;
                    // Send WOL packet.
                    await client.SendAsync(packet, packet.Length, ipEndPoint);
                }
                await _log.DebugAsync("Magic-Paket verschickt.");
            }
            catch (Exception ex)
            {
                await _log.ErrorAsync("Senden des Magic-Pakets ist fehlgeschlagen.", ex);
            }
        }