Author Topic: Gameserver Ping doesnt work?  (Read 4621 times)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Gameserver Ping doesnt work?
« 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.
« Last Edit: January 05, 2015, 07:56:54 AM by Rexima »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #1 on: January 05, 2015, 12:22:50 PM »
You can't ping a TCP socket. Only UDP.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #2 on: January 05, 2015, 01:12:03 PM »
Yes, but if i try to ping UDP, i get no answer, too.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #3 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.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #4 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:



And yes, i changed the udp port on the local hosted gameserver, too.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #5 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...
« Last Edit: January 13, 2015, 05:41:16 PM by ArenMook »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #6 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)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #7 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #8 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.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Gameserver Ping doesnt work?
« Reply #9 on: January 19, 2015, 01:06:29 PM »
Okay sup, thank you.