Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Ping not returning a value in most cases

Discussion in 'Multiplayer' started by Doghelmer, Mar 22, 2017.

  1. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    120
    I'm currently creating a server browser in my game that includes a ping column. I'm getting the ping using something like this:

    Code (csharp):
    1. Ping myPing = new Ping(myMatchIpAddress);
    2. while (!myPing.isDone)
    3.     yield return null;
    4. Debug.Log("Ping: " + myPing.time);
    The problem: This is only working on about 25% of the games that are being played right now. The others never return a value.

    myMatchIpAddress is being obtained from the game lobby's data, and was originally found on the server's end using something like this:

    Code (csharp):
    1. Network.Connect("http://www.google.com");
    2. while (Network.player.externalIP == "" || Network.player.externalIP == "UNASSIGNED_SYSTEM_ADDRESS")
    3.     yield return null;
    4. Network.Disconnect();
    5. Debug.Log("External IP: " + Network.player.externalIP);
    This seems to be getting the server's external IP address fine.

    Any ideas on why there seems to be such an issue pinging such a large number of these IP addresses? Am I going about this wrong in some way?
     
  2. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Many home routers, or computers in general, no longer respond to the PING cmd, so you can not get values back, and thus no data.
     
  3. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    120
    I figured it was something along those lines.

    Are there any known workarounds to this sort of thing, or is it just not feasible to do this anymore?
     
  4. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    You can get the ping to a "known" server that you run someplace - like a VPS, Cloud, EC2 - and "ping" that, and have all the players ping that known machine, which could then return the "average" ping, or something? You can also just punt and only show RTT/Ping for games the player is currently in... Or, from a running game, average the PING times in the game itself and report those to a server, or update the Lobby listing, rather then the client hitting the server itself... Pretty much all are kinda crappy solutions. Good luck!