question

avnishKumar avatar image
1 Vote"
avnishKumar asked CraigMitchell-6836 edited

Why,Ping functionality is not supported in UWP platform.

I added the System.Net.Ping NuGet Package to a blank UWP project and referenced the System.Net.NetworkInformationnamespace.

 Ping ping = new Ping();
 var rep = await ping.SendPingAsync("8.8.8.8");

Inner Exception:
PlatformNotSupportedException: Ping functionality is not currently supported in UWP.




windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

pesmith avatar image
2 Votes"
pesmith answered JensUweJhrig-9056 edited

I can't give a short answer, because it would be super controversial. But I can give you a good long answer.

Firstly, to bring everyone reading this up to speed: Ping is a very specific network protocol. You might think it's a UDP or maybe TCP based thing, but it's not: Ping is based on ICMP, a set of messages designed for communications between routers. Specifically, PING is built around the ECHO ICMP message (message type #8, and the reply is message type #0). Other ICMP messages are things like type #11, "Time Exceeded" (sent when a packet comes in with no time remaining), or type #4, "Source Quench" used when there's too much data coming in.

Fun historical diversion: in the original design of the internet, the idea is that each site (with possibly multiple real computers) would connect to the "internet message processor" (IMP); the imps were then connected together via phone lines. The ICMP messages were designed to go between the IMPs and not between the actual computers. Many IMPs also have a dedicated teletypewriter connected to the imp. So there's networking protocols designed for programs to use to connect to programs, and other network protocols designed just for the networking hardware.

So right away there's a problem: the PING message is unlike every other type of packet that the network codes uses. It's not TCP, it's not UDP, it's not a higher level protocol like ATOM or RSS or HTTP that we might want to support. Adding PING support would actually have required work.

The second problem is that PING is (no offense) somewhat overrated. Yes, it's often used to tell if a remote server is up. On the other hand, ICMP messages are routinely suppressed by firewalls, aren't routed by routers, and dropped entirely going in and out of a data center. Worse, a server can be effectively dead for use, and yet because of where PING is handled, it's still sending out replies.

This means that if you rely on PING to determine that a server is unreachable or dead, you'll have a bad time: there are plenty of cases where the server is perfectly fine and usable, but PING won't find it. And the flip side is true: just because PING can connect to the server, it doesn't mean that the server will actually talk to you.

The general network programming recommendation is: just try to connect to the server. If it fails, then you know it failed. If it works, you know it works. But trying to guess from PING if a server if OK isn't nearly as effective as you want it to be.

Source: I was the program manager (PM) on the team at Microsoft that decided to not support PING in UWP apps.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Seriously, please don't patronize developers.

Every other platform (win, Android, iOS, Linux) can ping from user apps.
The argument that ping is not reliable is weak.
And that MS was ignorant for developer demands for the WinRT/UWP platform for almost 9 years now, is incredibly disappointing.
No ping, no elevated mode, no possibilities to start win32 apps. systray is NOW finally possible.

Even MS doesn't use UWP for serious apps. Look at MS Office, VS (Code), Outlook.
Pure UWP is unusable for anything than very basic apps.
Finally in 2020 MS developed and released "Windows Terminal" their first more complex app for UWP. And guess what, they (MS developers) where struggling to get that working, because UWP is so limiting. They ended up, having a Win32 app doing all the important stuff, and the UWP app being "just" a nice frontend.

And that 8! years after the platform was introduced. Shame on you.

It almost seems some MS UWP folks worked hard, for UWP to fail.

2 Votes 2 ·

Thanks for your reply.

1 Vote 1 ·

@pesmith , Is trace-route also based on ICMP, and thus is not supported by UWP?

0 Votes 0 ·

Yes, that's why traceroute can't work in UWP apps with the current set of network APIs.

0 Votes 0 ·
65010773 avatar image
0 Votes"
65010773 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CraigMitchell-6836 avatar image
1 Vote"
CraigMitchell-6836 answered CraigMitchell-6836 edited

As a network engineer I disagree with the reasoning as to why ping (ICMP) is not supported in UWP. I would suggest that ping is one of the first tools used in the networking world to establish the status of the end to end routing, firewalls, DNS resolution etc that are playing a part in the success or lack of in establishing a connection to a router or server.

I actually started making a WPF app to help fellow networking engineers based on ping (ICMP) protocol. Sure, I might have expanded it to other protocols but the starting point was ICMP. The main aim of the app was to observe and alert the user as needed when an IP address had a change in the ping response, and to collect statistics on the ping responses. The app got half-way to being completed, then it was suggested I make a UWP version of the same app, but it wasn't long before I came across this exception:

System.Net.NetworkInformation.PingException: 'An exception occurred during a Ping request.'
Inner Exception: PlatformNotSupportedException: Ping functionality is not currently supported in UWP.

Unfortunately it is examples like this that force WPF developers to stay as WPF developers.

That said, I appreciate pesmith's response and understand we can't always have everything we want, but Microsoft really should align these platforms.

I also have to admit, that the real pain starts when I try to port this app to Android :D

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.