Reputation: 298
I have been recently writing a UDP server for a 2D shooter game I am making in C# and XNA for PC, which will update and send world data, entity data, chat data .etc when required.
A question recently sprinted into mind when I was creating a way for players to change their weapons; what would happen if in the occasion the packets send to the server requesting a weapon change were lost? This question then made me think of another question; how can I make a way for the client and server to acknowledge receiving certain packets or blocks of data?
So, I came up with the following simple looking solution to tackle this problem :
The proposed solution looks pretty good, but what would happen if in the occasion that the acknowledgement packet gets lost or if anything unintended happens to it?
Would a better solution to this problem be to create a server and client which use TCP and UDP; where TCP is used for data that needs to get there and arrive in order / in one peace, and UDP for data that needs to get there fast and can cope with loss or error?
If a TCP/UDP server and client is a better choice, what are the risks and how would I go around to implement that?
Thanks.
Upvotes: 2
Views: 707
Reputation: 5547
You need to be using TCP if you want to ensure packets are delivered. UDP does not guarantee delivery, but TCP has this built into the protocol.
Upvotes: 1