Author Topic: TNManager.Ping issues.  (Read 3430 times)

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
TNManager.Ping issues.
« on: November 09, 2015, 12:24:27 PM »
For some reason my TNManager.Ping never gets called back.

Calling TNManager.Ping
This code is within my Update method in my lobby.

  1. refreshPing -= Time.deltaTime;
  2. if (refreshPing <= 0)
  3. {
  4.     foreach (System.Net.IPEndPoint s in serverPings.Keys)
  5.     {
  6.         //it does infact reach here and yes "s" does return the IP address of the server
  7.         TNManager.Ping(s, onPingReceived);
  8.     }
  9.     refreshPing = 2f;
  10. }
  11.  
  12.  



onPingReceived

  1. void onPingReceived(System.Net.IPEndPoint endPoint, int mil)
  2. {
  3.     //never comes into this method.
  4.     if (serverPings.ContainsKey(endPoint))
  5.     {
  6.         serverPings[endPoint] = mil;
  7.         print("ping to server \"" + endPoint.ToString() + "\" = " + mil);
  8.     }
  9. }
  10.  

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNManager.Ping issues.
« Reply #1 on: November 10, 2015, 05:13:51 AM »
TNManager.Ping uses UDP, so make sure you're sending to your gameservers UDP port.

The TNLobbyClient returns the TCP port by default. You can trace this back to the gameserver in files TNUdpLobbyLink.cs and TNTcpLobbyLink.cs at the top of the ThreadFunction() function where the port argument for constructing mInternal and mExternal is set to the current TCP port.

edit:
You'd need to modify a bit to make the lobby server aware of the gameservers UDP *and* TCP port.
-TNServerList.cs [both the ServerList and Entry classes]
-TNUdpLobbyServer.cs
-TNTcpLobbyServer.cs
-TNUdpLobbyLink.cs
-TNTcpLobbyLink.cs

Should give you a good start. Maybe you can catch Aren's attention and have him include it in the next update :)
« Last Edit: November 10, 2015, 05:40:24 AM by cmifwdll »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.Ping issues.
« Reply #2 on: November 10, 2015, 08:35:05 PM »
If you follow a convention for port assignment, you should be able to handle this easily. For example I wrote a customized server executable for Windward that supports easier set of parameters such as "-public" to make the server automatically register with the master server list, making it visible to everyone. You can skip the UDP port assignment the same way, and simply assume that with a given TCP port, UDP will be X+Y, where "X" is your TCP port, and "Y" is some value. For example port 5127 for TCP will automatically assume port 5128 for UDP. Then when you get your server list from the lobby, you will know exactly which port to ping.

And yes, as cmifdll mentioned you need to have a UDP listener on the server for pings to work. TNServerInstance.Start lets you choose a UDP port as well.