Reputation: 18775
I can't send UDP messages from a UWP app on my Wi-Fi connected phone to a listener on a desktop machine.
A UWP app on a phone must send data to a process elsewhere on a network.
I can remote debug the app running on my phone. It executes the WriteString calls without incident but Wireshark isn't reporting the UDP traffic that ought to be generated.
Here is a sample of the problem code. For simplicity the IP address of the listener is hard coded and known to be correct at the time of testing. The phone was on the network and responded to pings at 192.168.1.10 immediately prior to the test.
DatagramSocket _ds = new DatagramSocket();
HostName _hostname = new HostName("192.168.1.3");
private async void Grid_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
using (var w = new DataWriter(await _ds.GetOutputStreamAsync(_hostname, "1967")))
w.WriteString("CC");
Debug.WriteLine("CC");
}
Peter Torr's answer and my comment on it supply the context for this addendum.
One might wonder why any sane person would wrap a stream around a small payload one-shot thing like a datagram. After days of mumbling about how stupid this is it finally dawned on me that it forced me to write my code in a way that doesn't make assumptions about the transport: I could switch to TCP with almost no code effort or consequences.
There may even be a requirement to do exactly this in support of network constraints and convenient administration (customer feedback). So what looks like an arbitrary complication of a simple thing is actually a very shrewd piece of design.
Upvotes: 0
Views: 584