Search Unity

Pinging a local IP from iOS

Discussion in 'Multiplayer' started by alperen-adastec, Feb 23, 2023.

  1. alperen-adastec

    alperen-adastec

    Joined:
    Aug 21, 2020
    Posts:
    6
    I'm not sure if this is the right sub-forum but here's my problem;

    I implemented a Wake-On-Lan class that wakes up 4 computers in my environment depending on the input fields on the UI. This is done via a UdpClient and I got it working both on Windows and iOS tablet. The next thing is to check if those computers are awake, by pinging their local IPs. Using System.Net.NetworkInformation is no problem at all for Windows. I get the PingReply with my tests in UnityEditor. But the same code built for iPad Air doesn't get a reply. I've also tried with SendAsync() in async methods. IPs are 192.168.1.10/12/75/76


    Code (CSharp):
    1.        
    2. private void Start()
    3. {
    4.     isCheckingResponse.Set();
    5.     listenerThread = new Thread(CheckResponse);
    6.     listenerThread.Start();
    7. }
    8. private void CheckResponse()
    9. {
    10.     var pingers = new Ping[]
    11.     {
    12.         new Ping(),
    13.         new Ping(),
    14.         new Ping(),
    15.         new Ping(),
    16.     };
    17.     var replies = new IPStatus[]
    18.     {
    19.         new IPStatus(),
    20.         new IPStatus(),
    21.         new IPStatus(),
    22.         new IPStatus()
    23.     };
    24.     while (isCheckingResponse.WaitOne(5000))
    25.     {
    26.         for (var i = 0; i < pingers.Length; i++)
    27.         {
    28.             var i1 = i;
    29.             try
    30.             {
    31.                 var pinger = pingers[i];
    32.                 var reply = pinger.Send(IPList[i]);
    33.  
    34.                 if (reply != null)
    35.                     replies[i] = reply.Status;
    36.                 else
    37.                 {
    38.                     ThreadDebugError($"IP:{IPList[i1]} does not exist!");
    39.                 }
    40.  
    41.                 if (replies[i] is IPStatus.Success)
    42.                 {
    43.                     Worker.wkr.AddJob(() => { Events.OnWoke.Invoke(i1); });
    44.                 }
    45.                 else
    46.                 {
    47.                     Worker.wkr.AddJob(() => { Events.OnSleep.Invoke(i1); });
    48.                 }
    49.             }
    50.             catch (PingException e)
    51.             {
    52.                 Console.WriteLine("Ping Problem: " + e.Message);
    53.             }
    54.             catch (NotSupportedException e)
    55.             {
    56.                 Console.WriteLine("Ping Problem: " + e.Message);
    57.             }
    58.         }
    59.     }
    60.     pingers.ToList().ForEach(_=>_?.Dispose());
    61. }
    62.        
    63.  
    Checked this but I don't have another build running on LAN, just some computers to check if they're on.
    https://forum.unity.com/threads/c-detecting-connected-devices-through-lan.297115/
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    What kind of message is that Ping? Is this an ICMP Ping? Maybe it's not supported by Unity on iOS. Or it could be that your router doesn't forward this between WiFi and ethernet connections.
     
  3. alperen-adastec

    alperen-adastec

    Joined:
    Aug 21, 2020
    Posts:
    6
  4. junaid-groketech

    junaid-groketech

    Joined:
    Sep 1, 2022
    Posts:
    1
    Hi, were you able to find a solution?