Messages not arriving to server in order when using ConnectWithSimulator

Hi,

I’ve been working on implementing client-side prediction for an FPS, but I’ve run into some problems using the messaging system in Unet. After debugging for awhile I found out that when using ConnectWithSimulator with latency my messages from the client weren’t arriving in proper order at the server. I have packet loss set to 0 for the simulation, and with a larger latency value the misordering is larger. Even if the messages are buffered at one point I would assume that it would be a queue with the first that arrive being the first that are read by the server.

To debug this I built a simple test script that can be easily run.

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class MessageTest : MonoBehaviour {

    [SerializeField]
    bool useSimulator;

    [SerializeField]
    float packetLoss = 0;

    [SerializeField]
    int latency = 0;

    public class MsgTest : MessageBase
    {
        public int index;
    }

    NetworkClient client;

    void InitializeClient()
    {
        client = new NetworkClient();

        if (useSimulator)
            client.ConnectWithSimulator("localhost", 7777, latency, packetLoss);
        else
            client.Connect("localhost", 7777);
    }

    int i = 0;

    void Update()
    {
        if (client != null && client.isConnected)
        {
            client.Send(MsgType.Highest + 1, new MsgTest() { index = i });
            i++;
        }
    }

    void InitializeServer()
    {
        NetworkServer.Listen(7777);

        NetworkServer.RegisterHandler(MsgType.Highest + 1, ReceiveFromClient);
    }

    void ReceiveFromClient(NetworkMessage netMsg)
    {
        var msg = netMsg.ReadMessage<MsgTest>();

        Debug.Log(msg.index);
    }

    void OnGUI()
    {
        if (!NetworkServer.active)
        {
            if (GUI.Button(new Rect(400, 20, 200, 20), "Init Server"))
            {
                InitializeServer();
            }
        }

        if (client == null || !client.isConnected)
        {
            if (GUI.Button(new Rect(100, 20, 200, 20), "Client Connect"))
            {
                InitializeClient();
            }
        }
    }
}

When I run this with 100 latency and 0 packet loss I get:

0
1
2
3
4
5
11
6
13
7
8
9
10
12

Is this just an issue with the simulator, or should I expect this in real-world conditions with latency?

Thanks,
Erik

Hm, looks like a bug in simulator. Report it please.

In real world you are very rare can expect it. This can be happened if one of routers drop packet due queue overfull (but simulator has packet loss parameter to simulate this) and if other routing path has been chosen for ip packet. (ip1 path routers user1-a-b-c-user2, ip2 path user1-f-g-e-user2) which is very rare…

Thanks for the reply @aabramychev . I’ve submitted a bug report on the problem. Sometime today I’ll run a test with a remote client.

EDIT: I tried this with a remote connection, and everything is in order. Good stuff!