0
\$\begingroup\$

Tcp is connection based so it's really good for chat or login or anything that needs reliability. Udp should be used for lots of small packets like position packets... The problem is that in a game like what I'm doing right now (terraria like), I can't decide what to use and how to use it properly. I though about using both at the same time, but can't find a way to ensure the udp "connection" will work.

If I were to choose UDP, is there a way I could make a "connection" out of it? to rely on it for login or chat messages?

And if I were to use TCP, would there be a way to speed it up?

More info : I'm doing this in C#.NET with XNA (I know it's no longer developped but I like it :P). I would also like to use Serialized objects (.Net BinaryFormatter), but it uses streams, and stream are only available in TCP... which makes it more attractive...

Thanks a lot!

\$\endgroup\$
1
\$\begingroup\$

Don't use TCP and UDP at the same time. I would recommend you to use UDP for everything, and some way of knowing when packets get lost.

I recommend a library called Lidgren for UDP programming: http://code.google.com/p/lidgren-network-gen3/

And using protocol buffers (there is a C# implementation of them) for serializing.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ +1 for recommending lidgren. The library uses UDP, but has the ability for reliable packets. \$\endgroup\$ – Luis Estrada Sep 15 '13 at 4:16
0
\$\begingroup\$

The old debate over UDP/TCP speed is over a decade old but still troubles newcomers.

As long as you remove nagle's algorithm and such, TCP will be fine for you. It is (IMO) also easier to use because all the checks (packet loss / orders) are already done. If you are unsure anyway, use some package/library that takes care of all of those things for you, there are ones where you can choose UDP or TCP as you want to too.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.