Find devices connected to wireless lan using Ping

Hello everyone, I search it for a long time but connot solve this problem. I am developing a game running on a PC which can build a wifi network and other device such as iPad or smart cellphone can connect to it. Now I want to list the ip address of the devices on wifi lan. I cannot find a good and fast way to do it. some solutions need Framework 4.0 or more, and other need to ping all the IP on the lan. Even when trying to ping the ip, it cannot work under unity3d, no matter using the Unity Ping or System.Net.NetworkInformation.Ping in C#.

The following is my code using Unity Ping. No matter whatever ip I use(even the ip of myself), the Ping.time is -1.

using UnityPing = UnityEngine.Ping;
.......
Update()
{
      UnityPing ping = new UnityPing(IPAdress);
      if (ping.isDone) 
               print("OK");
      print(ping.time.ToString());
}

So is there anyone can tell me why the ping cannot work? Or is there any better way to realize the function under Unity3d?

I doubt you really want to try to ping all devices on your network. All that will do is tell you whether or not they exist, not if they’re peers. I haven’t done any multiplayer work with Unity so I can’t help you out there.

As for your actual problem:

  1. Ping is an object. Creating a new one doesn’t call an actual ping function. The actual function is Ping() (it’s a constructor in this case).
  2. Ping is async and you’re going to want to poll the property isDone. You need a loop inside a coroutine to do that properly. You can’t use Update for that purpose.

You want something more like this:

function DoPing(ip : String) {
    var ping = Ping.Ping(ip);
    while (!ping.isDone) {
        yield;
    }
    Debug.Log(ping.time);
}

what if the result is faild? how Can I check it? isDone will be false if it failds? or isDone is true and the time is -1 when it failds?