参考のために、Xbox Oneをウェイクアップするために書いたC#ユニバーサルWindowsプラットフォーム(UWP)コードをいくつか示します。
public static async Task XboxWake(IPAddress ipAddress, string liveId, int retries = 5)
{
using (var socket = new DatagramSocket())
{
var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
await socket.BindServiceNameAsync("", connectionProfile.NetworkAdapter);
using (var stream = await socket.GetOutputStreamAsync(new HostName(ipAddress.ToString()), "5050"))
{
using (var writer = new DataWriter(stream))
{
for (int retry = 0; retry < retries; retry++)
{
byte[] payload = new byte[3 + liveId.Length];
payload[0] = 0x00;
payload[1] = (byte)liveId.Length;
for (int i = 0; i < liveId.Length; i++)
payload[i + 2] = (byte)liveId[i];
payload[payload.Length - 1] = 0x00;
byte[] header = new byte[6];
header[0] = 0xdd;
header[1] = 0x02;
header[2] = 0x00;
header[3] = (byte)payload.Length;
header[4] = 0x00;
header[5] = 0x00;
using (var ms = new MemoryStream(header.Length + payload.Length))
{
ms.Write(header, 0, header.Length);
ms.Write(payload, 0, payload.Length);
writer.WriteBytes(ms.ToArray());
}
await writer.StoreAsync();
await Task.Delay(1000);
}
}
}
}
}
(上記のコードのGitHub Gistリンク)