单触点原始插座 [英] Raw sockets in monotouch
问题描述
我正在尝试在MonoTouch中实现ping功能.
由于某些原因,System.Net.NetworkInformation
中的Ping
类在实际设备上不起作用,因此我决定切换到原始套接字并自己执行ping操作.
不幸的是,我在以下消息中收到访问被拒绝"消息:
I'm trying to implement ping function in MonoTouch.
for some reasons, Ping
class from System.Net.NetworkInformation
doesn't work on the real device, so I decided to switch to raw sockets and implement ping myself.
Unfortunately, I'm getting "Access Denied" message on:
socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp);
您知道如何在单点触控中执行ping吗?为什么我不能创建原始套接字?
Any idea how could ping be done in monotouch? And why can't I create raw sockets?
推荐答案
我没有尝试过原始套接字,但是您的访问被拒绝可能意味着它们在iOS中受到限制-就像它们允许 Ping
类在Linux系统的Mono上工作.
I have not tried raw socket but your Access Denied likely means they are restricted in iOS - just like they require root privilege on UNIX system. This is the same reason why, in some cases, it was not possible to directly (workaround exists) allow the Ping
class to work on Mono for Linux systems.
缺少Ping
是已知问题,可以通常通过使用可达到性一个>助手. 示例代码可在GIT上获得.
The lack of Ping
is a known issue and can generally be worked around by using the Reachability helper. Sample code is available on GIT.
这篇关于单触点原始插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!