31466

Raw sockets in monotouch

Question:

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);

Any idea how could ping be done in monotouch? And why can't I create raw sockets?

Answer1:

I have not tried raw socket but your <em>Access Denied</em> likely means they are restricted in iOS - just like they <a href="http://www.unix.com/unix-advanced-expert-users/108252-why-root-permissions-required-creating-raw-socket.html" rel="nofollow">require</a> <strong>root</strong> privilege on UNIX system. This is the same reason why, in some cases, it was not possible to <em>directly</em> (workaround exists) <a href="http://www.mono-project.com/Gendarme.Rules.Portability#FeatureRequiresRootPrivilegeOnUnixRule" rel="nofollow">allow</a> the Ping class to work on Mono for Linux systems.

The lack of Ping is a <a href="http://bugzilla.xamarin.com/show_bug.cgi?id=964" rel="nofollow">known</a> issue and can <em>generally</em> be worked around by using the <a href="https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs" rel="nofollow">Reachability</a> helper. <a href="https://github.com/xamarin/monotouch-samples/tree/master/ReachabilitySample" rel="nofollow">Sample</a> code is available on GIT.

Answer2:

You can use the Xamarin.iOS/MonoTouch bindings of SimplePing (which Apple says works on iOS).

<a href="https://github.com/theonlylawislove/MonoTouch.SimplePing" rel="nofollow">https://github.com/theonlylawislove/MonoTouch.SimplePing</a>

Check the test project for demo usage. Works on simulator and device.

Recommend

  • Camel example can't find org.apache.camel.impl.DefaultComponent
  • Having issues with matplotlib.pyplot over ssh
  • How To Add Maven Dependency (Android Studio)
  • How to Append RTF Text in RichTextBox, Win C#
  • UIMenuItem #selector method crash in wkwebview
  • Disable form button unless all text input fields are filled in
  • Mongo aggregation framework: what is the lock level of the last stage $out operation?
  • Is there a difference between a list and a tuple?
  • Android Studio issue when installing
  • java streams: straightforward reduce
  • @angular/platform-browser/platform-browser\"' has no exported member 'HammerLoader&#
  • What's the easiest way to read several ints from stdin if it's ok to fail?
  • NSOutlineView with NSTreeController bindings with core data
  • Unable to access local Web API from Visual Studio 2015 WIndows 10 Phone Emulator
  • Running web application developed using .NET 4.5 on Windows Xp clients
  • Why do I get IPC delays on 20% busy machine
  • Creating the shortest possible case-insensitive verification number
  • Why UIWebView work so slowly when loadHTMLString with UIWebView?
  • Java, How to refresh JTable in one frame from another frame
  • Replace Windows command FTP -s:E:\\FtpScript.txt with SFTP? [duplicate]
  • Use animate() with series of levelplots in R raster
  • javascript - Sum values from JSON
  • How to use MIPS load word
  • Rails Template Error with Heroku
  • Example of using Service Exists MSBuild task in Microsoft.Sdc.Tasks?
  • Circular Left Rotation Algorithm in C#
  • C# code can't “see” the methods in my C++ dll
  • When to use the tag in the head and body section of a html page? [duplicate]
  • read part of h5 dataset python