How to guarantee the data a user sent is received correctly on relayed matches

Hey everyone it’s me again,
in my game the socket received state will get lost on bad internet connection and the whole game will get stuck in a position where no one can play it,
so i want to make sure every state i send to the other user is received correctly, if not then retry it until it’s succesfull,
lagging happens in every multiplayer game for sure that’s something uncontrolable , but how do you hadle those laggs is my issue here.

what causes data to not be send or received ??
how to check if the data is not received ???
how to get back the received messages and handle it???

for additional information, i’m using unity SDK and relayed match, i send player postion in update.

thanks for any help on this

i would like to know more about full sync and how to implement it in unity so nothing gets lost when user gets back in.

Hi @sana2024.

How you deal with lag and lost packets really depends on context of your game and what is and isn’t considered mandatory network data.

For example, if you’re sending position updates every frame (possibly something you may want to reconsider, do you really need to send position updates 60+ times per second for every connected player?) it’s likely ok for a few of those to go missing, since the packets are coming in so thick and fast that the old ones are outdated by the time they arrive anyway. You would deal with this via interpolation and extrapolation on the recipient client end.

If however it’s a packet that is important like letting a player know that they’ve been knocked out of the round for example, you may wish to have the recipient acknowledge the receipt of the message and retry sending if the acknowledgement isn’t received in a certain amount of time.

A simplistic example of the above scenario is a “heartbeat” packet, sometimes called a “healthcheck”. Where one end sends a “PING” message and waits for the receiver to respond with a “PONG” message to verify that they received it.

As for what causes data to not be sent/received this could be anything from the device losing internet connection (think mobile phone going through a tunnel on a train) to a node along the way going down or dropping the packet unexpectedly. Most of the time these are things that are out of our control as developers, so the best thing we can do is program our network code defensively and with the expectation that some packets do indeed get lost in transit.

I hope this helps.

that’s interesting, thank’s a lot for the clear explanation,
i also have another question regarding this topic, will setting outgoing queue size, max message size and read and write buffer will affect this sending and recciving process??? because i want to understand the buffers more to know how to set it, will increasing the size of read buffer make the device to receive datas more correctly???

sorry for the unclear image hehe, but this is how i calculate things on my end
IMG_4074 Small

i put my queue size to 120 so this means 120 messages can be pending in the queue to be send to the other user (if that is correct) , and size of each message(pack) shouldn’t be bigger that 1500 Bytes accourding to the documentation, as i calculated the size of my messages i’m only sending a simple string of the postion something like this ( “2.5837282”), but regarding the small size, they are send frequently 30 to 60 time per update, this works fine on a stable internet but on bad network the messages will be send more slowly and this results in the buffer to be full and drop some packets,

this is what i understand from socket send and receive process, please correct me if i’m wrong in any part of this.
thanks for your effort and help on this,

You can find all of the relevant information regarding socket configuration parameters in our documentation here. However, I should note that the default values have been carefully and thoughtfully configured to provide the optimal socket connection feel for the vast majority of games, and I would therefore highly recommend not modifying these values unless you are absolutely sure you know it is necessary.

In your case it does sound like you are firing off too many position updates and the server/clients are not keeping up. I would advise reducing the amount of positional updates you send across the wire first, rather than modify the socket configuration parameters to try and account for the load.

i tried to reduce the update position, but i still want to perform a pingpong to detect more disconnections,
how can i use the nakama unity SDK PingPongManager ???

PingPongManager is not intended to be used by clients directly. It is intended to be an internal class used to check the health of the local socket connection.

Please can you summarise what it is you’re trying to achieve or what problem you’re currently experiencing now that the position updates are being sent less frequently?

Typically in a client relayed match you would designate one client as the “host” or “master client”. You could decide this based on an alphanumerical sort on the match presence user IDs and assign the first client in the list as the master for example.

This master could then be responsible for detecting client disconnects from the match by monitoring the socket’s presence event and acting accordingly.

There should be no need to establish a PING/PONG like packet loop between each individual client in the match; what I meant by giving that example was that you could have a master client wait for a recipient to send back an acknowledgement to the master, letting them know they received whatever important message was sent.

I should note that this is not usually necessary unless you have an explicit need to be able to resend particular messages or you need to explicitly act only when you are certain the message was received.