Live data from Hacker News

UDP vs TCP

gafferongames.com

141–150 of 198 posts

Re: UDP vs TCP

#141

Earlier quoted context omitted.

I always wondered why nobody used UDP for bulk data transfer: Ship all the chunks over with a sequential number identifying each, then when you've reached the end, have the client request any lost packets, then repeat the cycle until all are transferred. After all, the client doesn't need everything in sequential order if it knows the size, and it can deal with holes as long as they're eventually repaired. This gives…

> I always wondered why nobody used UDP for bulk data transfer 1) Bulk data transfer doesn't work over UDP. There is no flow control whatsoever with UDP and no guarantee, it sends stuff without distinction between a 56k uplink and a 10Gigabit LAN. The packet loss and lack of reliability are atrocious when you send non negligible amount of data. 2) You'd need to create a protocol on top of UDP to handle the basics (co…

>1) Bulk data transfer doesn't work over UDP.

Tell that to all of the people that use TsunamiUDP to do bulk data transfer. It uses TCP as a control protocol, but the data transfer is all UDP.

Re: UDP vs TCP

#142
I tried to build an UDP library once in C# with different methods (BeginReceiveFrom, ReceiveFromAsync, ReceiveFrom). You learn a ton and it's quite interesting. My goal was to recreate something similar to .NET remoting based on UDP.

But be aware that it's a daunting task, because there are so many things you need to handle all together: lost packets, reordered packets, duplicate packets, connection handshakes, session handling, reliable/unreliable channels, packet resends, random disconnects, reconnects, network congestion, spoofing, protocol hacking attempts, dos-attacks, banning, encryption, etc...

If you're writing an UDP library, you also need to think of performance, object pooling, connection buffers, threading/async issues and on top of that you also want to provide a nice API to the outside world for the client and server... Well, it gets messy...

If you're into this thing, I can advice you to look at haxe libraries. Learned a lot of them. There are very simple, idiomatic server/client-side implementations which are easy to follow, even if you don't know haxe [1][2].

[1]: https://github.com/svn2github/haxe/blob/master/std/neko/net/...

[2]: https://github.com/svn2github/haxe/blob/master/std/neko/net/...

Re: UDP vs TCP

#143
post #6

The main difference between TCP and UDP, as this programmer discovered, relates to quality of realtime service. Times to use UDP over TCP * When you need the lowest latency * When LATE data is worse than GAPS (loss of) in data. * When you want to implement your own form of error correction to handle late/missing/mangled data. TCP is best when * You need all of the data to arrive, period. * You want to automatically m…

People talk like most games use UDP, but they don't. Pretty much the only genre that does is First Person Shooters. MMOs (like world or warcraft) MOBAs (like Dota) RTSs (like Starcraft) Action RPGs (like Diablo) All of these are action games and use TCP. In most genres people would rather have the simulation pause when there is packet loss, and then run fast to catch up rather than have unreliable data about player l…

Not doubting, I see some other sources say the same thing, but why do you need to open UDP ports for WOW?

https://us.battle.net/support/en/article/firewall-proxy-rout...

Is it something that changed over time and that page is out of date? Is it just doing TCP over UDP for some esoteric cases?

Re: UDP vs TCP

#144
post #6

The main difference between TCP and UDP, as this programmer discovered, relates to quality of realtime service. Times to use UDP over TCP * When you need the lowest latency * When LATE data is worse than GAPS (loss of) in data. * When you want to implement your own form of error correction to handle late/missing/mangled data. TCP is best when * You need all of the data to arrive, period. * You want to automatically m…

also wherever you need real time there is mostly UDP in use, For SIP + RTP, webrtc is a little bit complicated but the real time part is based on UDP. all those have a mechanisms implemented for packet loss and how to handle it.

Re: UDP vs TCP

#145
post #143

Earlier quoted context omitted.

People talk like most games use UDP, but they don't. Pretty much the only genre that does is First Person Shooters. MMOs (like world or warcraft) MOBAs (like Dota) RTSs (like Starcraft) Action RPGs (like Diablo) All of these are action games and use TCP. In most genres people would rather have the simulation pause when there is packet loss, and then run fast to catch up rather than have unreliable data about player l…

Not doubting, I see some other sources say the same thing, but why do you need to open UDP ports for WOW? https://us.battle.net/support/en/article/firewall-proxy-rout... Is it something that changed over time and that page is out of date? Is it just doing TCP over UDP for some esoteric cases?

I don't know why it lists all three ports under both UDP and TCP for WoW. WoW uses 3724 over UDP for it's voice chat, but the other ports are only used with TCP.

Re: UDP vs TCP

#147
Anyone here knows what protocol should be used for mobile multiplayer games , provided they are real time and not turn by turn ? (think people playing on a decent 3g connexion).

I think you can't send a udp paquet to a phone because the carrier will block it, but i'm not sure.

Re: UDP vs TCP

#148
post #147

Anyone here knows what protocol should be used for mobile multiplayer games , provided they are real time and not turn by turn ? (think people playing on a decent 3g connexion). I think you can't send a udp paquet to a phone because the carrier will block it, but i'm not sure.

Yes an update on this topic for the mobile world would be very interesting.

Re: UDP vs TCP

#149
post #6

The main difference between TCP and UDP, as this programmer discovered, relates to quality of realtime service. Times to use UDP over TCP * When you need the lowest latency * When LATE data is worse than GAPS (loss of) in data. * When you want to implement your own form of error correction to handle late/missing/mangled data. TCP is best when * You need all of the data to arrive, period. * You want to automatically m…

Nobody ever mentions that UDP has one additional feature that TCP doesn't: preserving of message boundaries.

Re: UDP vs TCP

#150

The entire article makes me shudder in disbelief. It's aimed at people who don't know the difference between UDP and TCP (and possibly wet string). Yet he recommends they implement their own reliably protocol over UDP, and they avoid TCP because it's better to implement your own QoS? Why not add obtaining PhD in quantum mechanics just to round it out? It wouldn't alter the odds of pulling it off overly.

Regardless of the target audience, his point stands. Don't use TCP for "real time" games because when packet loss hits, TCP will make things worse by stopping to transmit later packets and then resend the old data which is now out of date.

It's definitely not an easy task for beginners, but these days you can pick up his library that implements this stuff.

https://github.com/networkprotocol/libyojimbo

Post reply on HN