1

I am trying to implement an UDP listener on a specific port but from any machine. I am trying to use the "new" Universal Windows project using Visual Studio 2015.

Using a WPF "old" type of project I could do the following:

public void StartListening()
{
    this.client = new System.Net.Sockets.UdpClient(5606);
    this.endpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 5606);
    this.client.BeginReceive(new AsyncCallback(receive), this);
}

private static void receive(IAsyncResult result)
{
    var self = ((UDPListener)result.AsyncState);
    var receivedBytes = self.client.EndReceive(result, ref self.endpoint);
    // do something with receivedBytes
    self.StartListening();
}

However using Universal Windows it seems to be quite different. There is no System.Net.Sockets.UdpClient any more. The only thing I can find is connecting to/from a client/server UDP things and stuffs using Windows.Networking.Sockets.DatagramSocket. With which I came up with the following:

public async void Connect()
{
    var listenerSocket = new Windows.Networking.Sockets.DatagramSocket();

    listenerSocket.MessageReceived += ListenerSocket_MessageReceived;

    await listenerSocket.BindServiceNameAsync("5606");
}

private void ListenerSocket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender, Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
{
    throw new NotImplementedException();
}

But this does not seem to do what I want. I never receive any data from a server that is running in the background. Where the WPF version does receive data.

What am I doing wrong? Is this not even possible any more? Can Universal Windows applications only receive data from other Universal Windows applications? Or am I just looking at the wrong things here?

Daan Timmer
  • 14,771
  • 6
  • 34
  • 66
  • Try this with TCP first so you get better diagnostics. And google "winrt local loopback" to learn about the connection scenarios that are blocked by the sandbox. – Hans Passant Jan 28 '16 at 12:25
  • To clarify. I am trying to read UDP data coming from the game Project Cars. I have no need at all for TCP and I only require one way traffic. – Daan Timmer Jan 28 '16 at 12:38
  • Do run that google query to find out why you cannot make this work. – Hans Passant Jan 28 '16 at 12:42
  • Thanks. What a complete heap of garbage that is then! How in the world is something like that expected to work then? Bah, humbug.. – Daan Timmer Jan 28 '16 at 12:47

1 Answers1

1

With UWP, they have a so-called "network isolation" mechanism that blocks UWP apps from doing networking with other apps on the same machine. They have tooling (and registry settings) to enable per-app loopback exceptions, but those are only available for client (not listening) sockets at the UWP app side.

(Shot themselves in the foot again)

George Birbilis
  • 2,782
  • 2
  • 33
  • 35