Skip to content

Instantly share code, notes, and snippets.

@HakanL
Created December 27, 2017 18:11
Show Gist options
  • Save HakanL/48cdc64a032445a9881b70fa11f43972 to your computer and use it in GitHub Desktop.
Save HakanL/48cdc64a032445a9881b70fa11f43972 to your computer and use it in GitHub Desktop.
C# code for waking up Xbox on 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);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment