NetworkTransport latency localhost

I’m doing some testing with the low level transport layer (UNET) and found out that Network.time is not the same on server and on client.
My understanding is that Network.time is suppose to give you the exact same time on client and server if both were called at the same time.
Now if that is true… then I am wondering how the network transport layer works since there’s about 30 MS time difference between the time on the Server and the time on the Client, keep in mind this is localhost…

question: is there meant to be 30 MS latency on localhost or am I doing something wrong?

I’m using on the client

NetworkTransport.Send ( m_hostId, m_connectionId, reliableChannel, buffer, buffer.Length, out error );

on the server

NetworkEventType networkEvent = NetworkTransport.ReceiveFromHost ( m_hostId, out connectionId, out channelId, buffer, 1500, out receivedSize, out error );

on the server.

Example gif below, first digits is the Network.time

(full code can be found here)
darrellbircsak.com/2015/12/28/checking-out-unitys-networktransport/
Help is appreciated.

Did a few other tests including System.DateTime.Now.Millisecond and it does appear that there is a 30 MS delay even on localhost… that seems quite high for just 1 message… am I doing something wrong?

Have a look at ConnectionConfig.SendDelay and ConnectionConfig.MinUpdateTimeout.
Also, I think to send instantly you can do NetworkTransport.QueueMessageForSending and then NetworkTransport.SendQueuedMessages.

1 Like

Thanks for the response, yeah that seems to be around the 20-30 ms which I was experiencing, I saw that SendDelay is used to combine packets together to reduce network stress but am not sure if I should keep it 10 as I am making a shooter game and adding 20-30 ping to some one could make it a lot less enjoyable for people.
(for movement inputs), i dont mind the 20 ms delay for chat and such.

(EDIT) after setting config.SendDelay to 0 and MinUpdateTimeout from 10 to 2 I still notice around 5-9 ms delay (2 of that would be from MinUpdateTimeout, any idea where that could come from?

whats the framerate of your game? both clients running at 60fps means you can get a delay at worst 32ms I think (double the fps delay).

right now the framerates are in the hundreds since it’s an empty project with just some network testing, I’m pretty happy with the ms its between 1 and 18 it seems. might be as good as I can get it.

Thanks for the help HiddenMonk :smile:

1 Like

Theres also GlobalConfig.ThreadAwakeTimeout that you can maybe lower to be faster? I dont really know how it works or what its default value is.
Youd pass the GlobalConfig into your NetworkTransport.Init(globalConfig…)

@HiddenMonk is right, try this. Another point - Do you take into account frame rate on receiver? Imagine that my FPS is one frame per hour, in this case latency could vary from 0 to 1 hour, with average 30 min, correct?

After tweaking the variables HiddenMonk suggested the network was quite a bit faster, I appreciate the help I got from you two, thanks.

1 Like