For my Unity game I have a Client-Server model, and I want both sides to ping each other repeatedly to make sure I know what latency between players is. In the server's case, a client connects and their details are logged. Their details are then used when the game creates coroutines. This coroutine starts a loop which pings and waits and pings and waits, etc, until the game ends.
However, it doesn't work. The debug messages are throwing up strange results. It attempts to ping to IP "::ffff:192.168.0.10", and then is waiting forever. I don't suppose the fact I am running this via Unity editor and another app window on the same machine should be an issue? What is the "::ffff" about in the IP it saves when a client connects? Is that the issue? If so, how can I best format it properly?
Yes, I need to add another loop in the coroutine to make it go forever. Once would be a nice start though.
CLIENT CONNECTS TO SERVER
// Recieve data from all.
NetworkEventType recData = NetworkTransport.Receive(out socketId, out connectionId, out channelId, buffer, bufferSize, out dataSize, out error);
switch (recData)
{
case NetworkEventType.ConnectEvent:
if (localConnectionId == connectionId)
{
// My active connect request approved.
Debug.Log("Connection request approved.");
}
else // New client.
{
string outIp;
int outPort;
UnityEngine.Networking.Types.NetworkID outNetwork;
UnityEngine.Networking.Types.NodeID dstNode;
byte outError;
NetworkTransport.GetConnectionInfo(socketId, connectionId, out outIp, out outPort, out outNetwork, out dstNode, out outError);
AllocateNewLobbyPlayer(socketId, connectionId, channelId, outIp, outPort);
}
break;
}
CREATE PING LOOP COROUTINES
for (int i = (Game.isServer) ? 1 : 0; i < lobbyPlayers.Length; i++)
{
if (lobbyPlayers[i] != null)
{
Debug.Log(" STARTED PING FOR " + i);
StartCoroutine(PingTest(lobbyPlayers[i].ip));
}
}
PING LOOP COROUTINE
protected IEnumerator PingTest(string ip)
{
Ping ping = new Ping(ip);
Debug.Log(" SENT PING " + ip);
while (!ping.isDone)
{
Debug.Log("WAITING");
yield return new WaitForFixedUpdate();
}
Debug.Log(" PING COMPLETED " + ping.time);
yield return new WaitForFixedUpdate();
}
DEBUG OUTPUT
STARTED PING FOR 1
SENT PING ::ffff:192.168.0.10
WAITING
WAITING
WAITING
etc, etc, etc...
ping 192.168.0.10
? \$\endgroup\$