Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Rexima on January 05, 2015, 06:13:21 AM

Title: Gameserver Ping doesnt work?
Post by: Rexima on January 05, 2015, 06:13:21 AM
Hi Aren,

i tried to get an Ping from the Gameserver, but i get no one?

This is my test script:

  1. using UnityEngine;
  2. using System.IO;
  3. using TNet;
  4. using System.Net;
  5.  
  6. public class Test : MonoBehaviour
  7. {
  8.     void Update()
  9.     {
  10.         if (Input.GetKeyDown(KeyCode.P))
  11.         {
  12.             TNManager.Ping(Tools.ResolveEndPoint("127.0.0.1", 6192), OnPing);
  13.         }
  14.     }
  15.  
  16.     void OnPing(IPEndPoint ip, int ms)
  17.     {
  18.         Debug.Log(ms);
  19.     }
  20. }

TCP: 6192
UDP: 6193

I tried both, but with no effect.
Title: Re: Gameserver Ping doesnt work?
Post by: ArenMook on January 05, 2015, 12:22:50 PM
You can't ping a TCP socket. Only UDP.
Title: Re: Gameserver Ping doesnt work?
Post by: Rexima on January 05, 2015, 01:12:03 PM
Yes, but if i try to ping UDP, i get no answer, too.
Title: Re: Gameserver Ping doesnt work?
Post by: ArenMook on January 06, 2015, 11:13:06 AM
UDP should work, assuming you use the latest TNet version and the port is actually reachable. Seems to work as expected on my end.
Title: Re: Gameserver Ping doesnt work?
Post by: Rexima on January 12, 2015, 10:45:36 AM
I have the latest version running.

I took your example and try it with this. Same result, no Ping answer:

(http://i.imgur.com/MR3zRkX.png)

And yes, i changed the udp port on the local hosted gameserver, too.
Title: Re: Gameserver Ping doesnt work?
Post by: ArenMook on January 13, 2015, 05:35:12 PM
OnGUI code runs several times per frame. Putting a Ping() in there is a very bad idea.

You can't ping the server from itself. Try running TNServer.exe, then doing a ping.
  1.                                 // NOTE: I am using 'internalAddress' here because I know all servers are hosted on LAN.
  2.                                 // If you are hosting outside of your LAN, you should probably use 'externalAddress' instead.
  3.                                 if (GUILayout.Button(ent.internalAddress.ToString(), button))
  4.                                 {
  5.                                         //TNManager.Connect(ent.internalAddress, ent.internalAddress);
  6.                                         //mMessage = "Connecting...";
  7.  
  8.                                         System.Net.IPEndPoint ip = new System.Net.IPEndPoint(ent.internalAddress.Address, serverTcpPort + 1);
  9.                                         TNManager.Ping(ip, OnPing);
  10.                                 }
Edit: Although trying the same thing myself I see that it's being sent out but I am not getting a response back in the TNet's base example. Looking into it...
Title: Re: Gameserver Ping doesnt work?
Post by: ArenMook on January 13, 2015, 05:46:10 PM
Ah yes, found the issue. Open up TNGameServer.cs, line 308:
  1. else if (buffer.size > 4)
Change it to be:
  1. else if (buffer.size > 0)
Title: Re: Gameserver Ping doesnt work?
Post by: Rexima on January 19, 2015, 08:01:20 AM
Thank you for this.

Can you tell me maybe, how to get the Ping from any player?

Should all players send every 5 or 10 seconds, to others players?

I want it, for the ingame TAB information, and for the lobby.
Title: Re: Gameserver Ping doesnt work?
Post by: ArenMook on January 19, 2015, 11:59:30 AM
The way I did it in Windward is I send a broadcast packet to everyone connected to the server -- a "who's there?" packet. Each client then responds with a private message to the player that sent the packet, sending their name, faction, ping, etc. The original player that sent the broadcast receives these packets one at a time and prints the result to chat.
Title: Re: Gameserver Ping doesnt work?
Post by: Rexima on January 19, 2015, 01:06:29 PM
Okay sup, thank you.