Networking not sequenced, - ReliableSequenced Qos in Transport Layer API?
Hi there, I'm trying to build a simple server and client application using unity and Transport Layer API. I request QosType.ReliableSequenced for both the client and server app, open up the connection, etc. In my server Update method I increase an int called iClock by 1 every frame and then after that send a message to the client up with the value of iClock like so:
public void SendPlayerClock(Player player)
{
Account account = player.account;
byte[] buffer;
byte error;
MemoryStream writeStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(writeStream);
writer.Write(PackageType.Clock);
writer.Write(iClock);
buffer = writeStream.ToArray();
NetworkTransport.Send(serverSocketId, player.iConnectionId, rsChannel, buffer, buffer.Length, out error);
}
In the client I receive the event via NetworkTransport.Receive in its Update method and display the iClock value via OnGui. At first it goes in order, but here's what happens:
At first the client sees the value increasing as it should
After some time, every once in a while it skips to a lower value and continues, in time it's getting worse and worse
If I move the focus away from the Editor, it seems to kind of display the same symptoms, but if I open an instance of a built client and focus on that one, the original one in the editor just stops, doesn't show any change in the counter, as soon as I put the focus back to it, it continues, but now it skips between high and low values.
What is going on? Both the client and the server have the runInBackground set to true. Am I misunderstanding the ReliableSequenced QoS or some threading stuff going on? It seems it's heavily reliable on the framerate of the application.
Here is how I open the socket:
//Initialize the Unity Transport Layer API
public void InitializeNetworkCode()
{
Debug.Log("Initializing Network Code");
Application.runInBackground = true;
// Init Transport using default values.
NetworkTransport.Init();
// Create a connection config and add a Channel.
ConnectionConfig config = new ConnectionConfig();
rsChannel = config.AddChannel(QosType.ReliableSequenced);
// Create a topology based on the connection config.
HostTopology topology = new HostTopology(config, serverSettings.MaxNumPlayers);
int iChannel = 8801;
// Create a host based on the topology we just created, and bind the socket to port 12345.
serverSocketId = NetworkTransport.AddHost(topology, iChannel);
}
Here is the receiving code:
NetworkEventType evnt = NetworkTransport.Receive(out outHostId, out outConnectionId, out outChannelId, buffer, bufferSize, out receiveSize, out error);
Edit After some testing I can see that in this scenario, if I change the QoS, the behavior is as follows: Unreliable - least amount of skipping ReliableSequenced - moderate amount of skipping AllCostDelivery - completely crazy
Why is that? How can I have a truly reliable and sequenced way of delivering data?
Answer by slingchilders · Dec 08, 2016 at 06:51 AM
I fell victim to my own poor reading comprehension, and misunderstood the QoS specs in the Unity Documentation. For what I needed I should have gone with StateUpdate I was really confused with the use of the word Sequenced in some of these - in what way is it sequenced if I was really clearly receiving older packets? Does that have to do with how I receive those fast messages inside Update?
So for anyone who has a similar problem, this goes to show that you should really think about what kind of information you are sending and how it should be treated logically within the game. Found this which shows what typical applications of each QoS are:
https://blogs.unity3d.com/2014/06/11/all-about-the-unity-networking-transport-layer/
Your answer
Follow this Question
Related Questions
Error when using NetworkList "Don't know how to serialize List`1 " 0 Answers
local scale network 0 Answers
[UNet] Network Animator transition stutters 0 Answers
How to make my game multiplayer? 1 Answer
UDP Client receiving Disposed error 0 Answers