Author Topic: Ping a remote gameserver, thats listed on my serverbrowser.  (Read 4691 times)

ibaanb

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 17
    • View Profile
I want to ping a remote gameserver, thats listed on my serverbrowser.
And I do it like this

  1. TNManager.Ping(svList[i].internalAddress, OnPing);

But OnPing not get call.
So can you tell me how to do it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile

ibaanb

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Ping a remote gameserver, thats listed on my serverbrowser.
« Reply #2 on: July 14, 2014, 03:56:10 AM »
I've add your code

  1. public void Ping (IPEndPoint udpEndPoint, OnPing callback)
  2.     {
  3.         onPing = callback;
  4.         mPingTime = DateTime.Now.Ticks / 10000; // <-- this was missing
  5.         BeginSend(Packet.RequestPing);
  6.         EndSend(udpEndPoint);
  7.     }

to TNGameClient's Ping() function
and

  1. case Packet.RequestPing:
  2. {
  3.     BeginSend(Packet.ResponsePing);
  4.     EndSend(ip);
  5.     break;
  6. }

to TNTcpLobbyServer.cs
but still got the same result not thing happen.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ping a remote gameserver, thats listed on my serverbrowser.
« Reply #3 on: July 15, 2014, 01:30:17 AM »
1.9.6 has this code built-in, and I tested the pinging using this script:
  1. using UnityEngine;
  2. using System.IO;
  3. using TNet;
  4. using System.Net;
  5.  
  6. public class Test : MonoBehaviour
  7. {
  8.         string text = "";
  9.  
  10.         void Start ()
  11.         {
  12.                 text = "UDP: " + TNManager.StartUDP(Random.Range(10000, 50000));
  13.         }
  14.  
  15.         void Update ()
  16.         {
  17.                 if (Input.GetKeyDown(KeyCode.P))
  18.                 {
  19.                         TNManager.Ping(Tools.ResolveEndPoint("127.0.0.1", 5129), OnPing);
  20.                 }
  21.         }
  22.  
  23.         void OnPing (IPEndPoint ip, int ms)
  24.         {
  25.                 text += "\nPing: " + ms;
  26.         }
  27.  
  28.         void OnGUI ()
  29.         {
  30.                 GUILayout.Label(text);
  31.         }
  32. }
I just start the server via the executable, attach this script to some game object, hit Play and press "P".

ibaanb

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Ping a remote gameserver, thats listed on my serverbrowser.
« Reply #4 on: July 22, 2014, 06:45:32 AM »
Ping is working.
Thank you.