Tuesday, October 23, 2018

networking - Does it make sense to use both TCP and UDP at once?


After reading Is UDP still better than TCP for data-heavy realtime games?, I'm wondering if it makes sense to use both TCP and UDP at the same time, but for different things:




  • TCP for sending information that is sent infrequently, but should be guaranteed to arrive reliably.
    Such as score updates, a player's name, or even the on/off state of a light in the game world.





  • UDP for transmitting information that is updated constantly and can be lost occasionally, since newer information is always on the way.
    Such as position, rotation, etc.




Is this a reasonable idea? What are the possible drawbacks?
Are there better ways to handle this?



Answer



It results in packet loss for UDP due to contention between the two protocols - remember that UDP is not guaranteed delivery, while TCP is. More TCP packets will get through while UDP suffers - TCP induces UDP packet loss. There has also been the (historical) idea that router infrastructure favours TCP over UDP, though I doubt that is still true by this late stage.


I think you'd be better off finding one of the connection-oriented UDP protocols that is out there for use in games and the like, that offers you some of the benefits of TCP with none of its downsides. There are a few such, usually with a whitepaper detailing each concept.


An example of those is the open source Enet library, its primary feature being optional reliable, in-order delivery of packets over UDP.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...