fredatgithub / Xamarin.SimplePing

SimplePing demonstrates ping (ICMP) send and receive.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Xamarin.SimplePing

Build Status

SimplePing demonstrates ping (ICMP) send and receive.

A Xamarin.iOS and Xamarin.Mac binding for the Apple sample: https://developer.apple.com/library/content/samplecode/SimplePing

On most platforms ping requires privileges (it's implemented with a raw IP socket). Apple platforms include a special facility that allows you to ping without privileges. Specifically, you can open a special, non-privileged ICMP socket that allows you to send and receive pings.

To use the SimplePing class:

  1. create an instance of the SimplePing class and keep a reference to that instance
  2. set the Delegate property or the Started event.
  3. call Start().
  4. if things go well, your delegate's DidStartWithAddress() method, or the Started event, will be called; to send a ping, call SendPing()
  5. when SimplePing receives an ICMP packet, it will call the DidReceivePingResponsePacket() method, or the ResponseRecieved event

SimplePing can be used from any thread but the use of any single instance must be confined to a specific thread. Moreover, that thread must run its run loop. In most cases it's best to use SimplePing from the main thread.

var pinger = new SimplePing("www.apple.com");

pinger.Started += (sender, e) => {
    var endpoint = e.EndPoint;
    pinger.SendPing(null);
};

pinger.ResponseRecieved += (sender, e) => {
    var seq = e.SequenceNumber;
    var packet = e.Packet;
};

pinger.Start();

About

SimplePing demonstrates ping (ICMP) send and receive.

License:MIT License


Languages

Language:C# 52.7%Language:PowerShell 30.6%Language:Shell 16.7%