0
\$\begingroup\$

I'm currently working on a networking framework for Unity3D in order to simplify making multiplayer games. I'm using UDP for any kind of synchronisation and unimportant data.

My question is: how do I send reliable packets such as RPCs or object instantiation? Should I use TCP for that or should I go about writing my own reliable protocol on top of UDP?

Thanks in advance!

\$\endgroup\$
1

1 Answer 1

2
\$\begingroup\$

Running both TCP and UDP in parallel just leads to problems. Also, you might not need all the reliability features of TCP, so it might be overkill anyway.

Most games solve this problem by replicating those TCP reliability features they really need on the application level.

  • Do you have the concept of persistent connections? Add a connection-ID to every message.

  • Do you need delivery guarantee for certain messages? Have the receiver reply to these message with a confirmation. Resend any message when the confirmation doesn't arrive within a given timeframe.

  • Do you need to know the order in which messages were sent? Add sequence numbers to your UDP messages.

  • Do you need guarantee that sequences are processed in sequence? Add sequence numbers and allow the receiver to re-request a message with a given sequence number. Have it do that when a missing sequence number doesn't arrive within a given timeframe.

Implementing all of this on your own gives you far more control over what actually happens on the network level than just letting TCP handle it. But the bottom line is, real-time networking is complicated. Every game developer is well-advised to not reinvent the wheel and instead take a look at what reliable UDP libraries for game development are available for their programming language.

\$\endgroup\$
2
  • \$\begingroup\$ The I Shot You First: Networking The Gameplay of Halo: Reach is one of the best videos I've seen related to video game networking. There is a section concerning networking and TCP vs UDP and reliability. They use multiple tiers. One they would send 3 duplicate packets hoping one or more arrived with no further follow-up. \$\endgroup\$ Mar 31, 2020 at 22:49
  • 1
    \$\begingroup\$ Also, mixing TCP and UDP won't cause problems. Because your infrastructure (router, ISP, etc.) is already mixing those! It's only when network bandwidth becomes saturated would you see problems. \$\endgroup\$ Mar 31, 2020 at 22:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .