EDIT: So the formatting on the code is a bit broken due to how the forum is deciding to format it. Assume the two chunks of code are each a contiguous function.
Hey all,
I’m using Windows 10 UWP to development a new Plex widget. I’m in the process of implementing GDM and I’m having some trouble figuring out the DatagramSocket implementation for multicasting to the GDM address.
My code looks something along these lines:
public async Task ClientScan() { //Set up and connect to the group HostName hostName = new HostName("239.0.0.250"); var socket = new DatagramSocket(); socket.Control.MulticastOnly = true; await socket.BindServiceNameAsync("32412"); socket.JoinMulticastGroup(hostName); socket.MessageReceived += received;
//Broadcast the search string
var outputStream = await socket.GetOutputStreamAsync(hostName, "32412");
DataWriter writer = new DataWriter(outputStream);
writer.WriteString("M-SEARCH * HTTP/1.0
");
await writer.StoreAsync();
}`
The code successfully publishes and I can see the other search requests that the server, my phone, etc. are sending out. But for whatever reason I’m not getting the response back from the players themselves. I’ve played with a Python implementation of this and I wrote my own straight .Net implementation that worked but I’m having a hard time figuring out what I’m doing here.
For reference this is what I took a few minutes to whip up using the .NET API’s that aren’t available in UWP. This example works.
class Program { static void Main(string[] args) { UdpClient client = new UdpClient(); IPAddress addr = IPAddress.Parse("239.0.0.250"); client.JoinMulticastGroup(addr, 50); IPEndPoint iep = new IPEndPoint(addr, 32412);
var buffer = Encoding.ASCII.GetBytes("M-SEARCH * HTTP/1.1");
client.Send(buffer, buffer.Length, iep);
Thread.Sleep(100);
Byte[] data = client.Receive(ref iep);
string strData = Encoding.ASCII.GetString(data);
Console.WriteLine(strData);
client.Close();
}
}`
Any help from those with experience working with the DatagramSocket in .Net would be very appreciated!