单点触控中的 ping
我想知道为什么某些单点触控功能在模拟器中运行良好,但在真实设备上却失败? 相同的 Ping 类。它在模拟器上完美运行,但在设备上失败。有什么区别?有没有办法让它在设备上工作?
此外,我还找到了这篇关于如何在 mac OS 中实现 ping 的文章: http://developer.apple.com/library/mac/#samplecode/SimplePing/Listings/SimplePing_m.html#//apple_ref/doc/uid/DTS10000716-SimplePing_m-DontLinkElementID_5
会吗可以将此代码移植到 monotouch 吗?老实说,我还没有尝试过它是否可以在 iOS 上运行,但我不明白为什么它不能在 iOS 上运行。
附言。我了解 Reachability 类,是的,我确实在我的项目中使用它而不是 ping!
I'm wondering why does some monotouch features works well in simulator but fails on real device?
the same Ping class. it works perfectly from simulator but fails on the device. What is the difference? it there a way to make it work on device?
More over, I've found this article on how to implement ping in mac OS:
http://developer.apple.com/library/mac/#samplecode/SimplePing/Listings/SimplePing_m.html#//apple_ref/doc/uid/DTS10000716-SimplePing_m-DontLinkElementID_5
will it be possible to port this code to monotouch? being honest, I havent yet tried if it works on iOS, but I dont see anything why wouldn't it work there.
PS. I know about Reachability class, and yes, I do use it in my projects instead of ping!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这很可能是 iOS 允许您执行的操作的问题。
这里来自一位尝试使用原始套接字实现 ping 的人,但遇到了 iOS 限制。
原始错误报告指出:“要执行 ping 操作,需要 linux内核功能 (capget) 或设备上不存在的 ping 二进制文件。”换句话说:root 访问权限。
这里是一种解决方法,但它不是 ping 实现。
也就是说,看起来有人尝试将 SimplePing 示例成功移植到 iOS,所以也许毕竟这是可能的 - 但它只是没有成为研究它的优先事项(毕竟 Reachability 类是可用的)。
This is most likely an issue with what iOS allows you to do.
Here is from one guy who tried to implement ping using raw sockets, and ran into iOS restrictions.
The original bugreport states that: "To do a ping requires a linux kernel capability (capget) or the ping binary on the device which doesn't exist." In other words: root access.
Here is a workaround, but it's not a ping implementation.
That said, it looks like somebody tried to port the SimplePing sample to iOS with success, so maybe it is possible after all - but it just hasn't been a priority to look into it (the Reachability class is after all available).
MonoTouch 的 SimplePing 现已推出。
https://github.com/theonlylawislove/ MonoTouch.SimplePing
只需将此 git 存储库作为子模块添加到您的项目中,然后“添加现有项目”并将“MonoTouch.SimplePing”添加到您的项目中。在“MonoTouch.SimplePing.Test”项目中,有一个名为“SimplePingHelper”的小帮助程序类,可以让事情变得更容易一些。
然后使用以下代码。
该解决方案适用于模拟器和我测试过的每台设备。
不要使用互联网上发现的任何“RawSocket”黑客技术。它充满了异步代码的错误以及它在某些设备上运行而不是在其他设备上运行的问题。在我拔出头发后,我想我应该移植 SimplePing 项目,因为我发现它确实有效。
享受!
SimplePing for MonoTouch is now available here.
https://github.com/theonlylawislove/MonoTouch.SimplePing
Simple add this git repo as a submodule to your project, then "Add existing project" and add the "MonoTouch.SimplePing" to your project. There is one small helper class that will make things a little easier in the "MonoTouch.SimplePing.Test" project called "SimplePingHelper".
Then use the following code.
This solution works in the simulator and every device I have tested.
Do not use any of the "RawSocket" hacks found on the internet. It is riddled with bugs with async code and issues with it working on some devices and not others. After pulling my hair out, I figured I would port that SimplePing project since I discovered that it does actually work.
Enjoy!
MonoTouch 要求操作系统(例如本例中的网络堆栈)执行其命令。 iOS 模拟器和设备之间的操作系统允许不同(并且确实如此),并且在运行时的行为也不同。
只是为了再次强调 Apple SDK 提供的 iOS 模拟器不是模拟器这一主要事实。它甚至没有尝试模拟设备的大多数限制。例如:
执行 x86 代码,而不是 ARM 代码(就像 Android 模拟器需要的那样);
允许 JIT'ing(这很好,因为它允许 MonoTouch 非常快速地构建并在模拟器下进行调试)。这在设备上是不允许的(甚至是不可能的),我们必须使用AOT编译;
提供对文件系统的完全访问权限(当前用户可以读取的数据);
不为某些特定设备功能(例如加速计)提供模拟支持;
列表还在继续...
有些差异很大(它比运行 ARM 代码的仿真器快得多),而其他差异可能相当有限(例如,缺乏在某些情况下支持硬件功能)。
MonoTouch ask the operating system, e.g. the networking stack in this case, to do its bidding. The operating system is allowed to be different (and is) between the iOS simulator and devices and also behave differently at runtime.
Just to re-enforce the main fact that Apple SDK provides an iOS simulator is not an emulator. It does not even try to emulate most of the restrictions of devices. E.g. it:
execute x86 code, not ARM code (like the Android emulator would require);
allows JIT'ing (which is nice since it allows MonoTouch to build really fast to debug under the simulator). That is not allowed (or even possible) on devices and we must use AOT compilation;
provide full access to the file system (as much as the current user can read);
does not provide simulated support for the some specific devices features (e.g. accelerometer);
the list goes on...
Some of the differences are great (it's much faster than an emulator running ARM code would be) while others can be pretty limiting (e.g. lack of support for hardware features) in certain scenarios.