I've made a little C# server which receives UDP packets and shows me the incoming information. I want to make an authoritative server in C# which simulates character movement and interaction in a 2D real-time world and sends information back to a Unity game client where the information is then represented.
My question is: How does my server know how long a button is pressed in real-time (example: right arrow key to move character right)?
My guess is that the client would send a UDP packet to the server on-key-press saying move-this-direction. The server would then simulate the character moving and new positional information is constantly sent back. When the Client releases the key a new UDP packet is sent to the server saying the movement key has been released thus stop-moving-this-direction. BUT the problem is UDP unreliability and the lag between letting the key press up, and the server knowing that the key press is up; which would make the character keep moving for a period of time after letting go of the key - is this solved with proper movement interpolation?.
Any ideas or information sources how to properly handle sending arrow key movement data to a authoratative server?