本文介绍了ICMP平在WinRT中 - 这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何做一个ICMP的ping在WinRT的现代UI应用程序

How to do an ICMP ping in a WinRT Modern UI application?

中国平安没有在WinRT中实现当前(请参阅相关的问题的 )

  • Use a WCF Service
  • Call Javascript which then calls an ActiveX component
  • Give up (here)

瓦西里的使用HTTP来'平'使用StreamSocket支持使用TCP套接字网络通信的特定端口上的网络服务器。

Vasily here uses http to 'ping' a webserver on a specific port using StreamSocket which supports network communication using a TCP socket.

也许的 s是最高级别的API我,如果我想要写我的使用自己的ICMP库的WinRT ..

Perhaps Windows.Networking.Sockets is the highest level API I have to use if I want to write my own ICMP library for WinRT..

的实现使用的System.Net.Sockets使ICMP回应请求 - 在标准的.NET

This implementation uses System.Net.Sockets to make an ICMP echo request - in standard .NET

的WinRT的示例使用Windows.Networking.Sockets .DatagramSocket类来创建一个UDP套接字。我想,我需要的是原始套接字做ICMP。

This WinRT sample uses the Windows.Networking.Sockets.DatagramSocket class to create a UDP socket. I think what I need is raw sockets to do ICMP.

这甚至可能在WinRT的沙箱ICMP的ping?

Is this even possible in the WinRT sandbox to ICMP ping?

推荐答案

是这样的:

try
            {
                using (var tcpClient = new StreamSocket())
                {
                    await tcpClient.ConnectAsync(
                        new Windows.Networking.HostName(HostName),
                        PortNumber,
                        SocketProtectionLevel.PlainSocket);

                    var localIp = tcpClient.Information.LocalAddress.DisplayName;
                    var remoteIp = tcpClient.Information.RemoteAddress.DisplayName;

                    ConnectionAttemptInformation = String.Format("Success, remote server contacted at IP address {0}",
                                                                 remoteIp);
                    tcpClient.Dispose();
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147013895)
                {
                    ConnectionAttemptInformation = "Error: No such host is known";
                }
                else if (ex.HResult == -2147014836)
                {
                    ConnectionAttemptInformation = "Error: Timeout when connecting (check hostname and port)";
                }
                else
                {
                    ConnectionAttemptInformation = "Error: Exception returned from network stack: " + ex.Message;
                }
            }
            finally
            {
                ConnectionInProgress = false;
            }



完整的源代码在这里:的

这篇关于ICMP平在WinRT中 - 这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:50