我不知道如何使用物联网发送 WOL (WakeOnLan)。
看起来我应该使用 DatagramSocket,但是我可以在网上找到的所有示例都使用 UDPClient。
如何在 IoT 中发送 WOL (UDP)?
谢谢。
我不知道如何使用物联网发送 WOL (WakeOnLan)。
看起来我应该使用 DatagramSocket,但是我可以在网上找到的所有示例都使用 UDPClient。
如何在 IoT 中发送 WOL (UDP)?
谢谢。
要在 WinRT 应用程序中发送魔术包,您确实需要使用 Windows.Networking.Sockets API 中的 DatagramSocket。这是我不久前写的一个基本解决方案:
public async void SendMagicPacket(string macAddress, string ipAddress, string port)
{
DatagramSocket socket = new DatagramSocket();
await socket.ConnectAsync(new HostName(ipAddress), port);
DataWriter writer = new DataWriter(socket.OutputStream);
byte[] datagram = new byte[102];
for (int i = 0; i <= 5; i++)
{
datagram[i] = 0xff;
}
string[] macDigits = null;
if (macAddress.Contains("-"))
{
macDigits = macAddress.Split('-');
}
else if (macAddress.Contains(":"))
{
macDigits = macAddress.Split(':');
}
if (macDigits.Length != 6)
{
throw new ArgumentException("Incorrect MAC address");
}
int start = 6;
for (int i = 0; i < 16; i++)
{
for (int x = 0; x < 6; x++)
{
datagram[start + i * 6 + x] = (byte)Convert.ToInt32(macDigits[x], 16);
}
}
writer.WriteBytes(datagram);
await writer.StoreAsync();
socket.Dispose();
}