TCP vs UDP

Blitz3D Forums/Blitz3D Beginners Area/TCP vs UDP

Imperium(Posted 2013) [#1]
What are your thoughts?
http://www.diffen.com/difference/TCP_vs_UDP

How much slower is TCP with today's broadband connections? For a multiplayer game involving no more than 8 people, TCP on an outgoing connection of at least 846 Kbps (which is 106 kB/s) should be fine for a average game. Would you agree or disagree?

I'm looking over the "CreateTCPServer (port) " in the Blitz help file, where can I find out more about using UDP with Blitz? Is this easier or harder than TCP or is the principles basically same?


Yasha(Posted 2013) [#2]
People have made successful TCP-based games in the past, so it can be done if you really want to.

But why bother? By building your own reliability and ordering layers on top of UDP instead, you can have all of the advantages of TCP while being able to "dial down" the effects in a gradual fashion depending on your usage scenario, e.g. ditch reliability for action gameplay while keeping both around for the chat client. The fact is, most of the time for gaming purposes TCP's features are still more of a hindrance than a help... and just because the hardware can compensate for them is not by itself a reason to put up with them when you don't need to.

Use a library like Rottnet and the hard work (that is, making UDP both ordered and reliable, to the extent that is realistically required) is done for you already.


Imperium(Posted 2013) [#3]
Actually I just downloaded Rottnet the other day.
I agree that using TCP just because the hardware can compensate is poor logic. Seems like UDP is the way to go.

More on TCP vs. UDP.
http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/

In defense of TCP let's say you had a really good server and your game was a action packed FPS. Would TCP still be a poor choice? According to the link above the answer would still be "NO".

But they do raise a interesting point:
"I note runescape uses TCP and our warehouse staff are always playing the bloody game. That’s a perfect example, no doubt the creators want it to work anywhere ANYONE can get the internet."

Could using UDP potentially limit how many users could play my game?


RemiD(Posted 2013) [#4]
From my understanding :
UDP is a protocol to send a packet from one emitter to a receiver, that's it. The packet may be lost, the packet may be corrupted, the packet may arrive in the wrong order (a previously sent packet may arrive after a recently sent packet)

TCP is a protocol to send a packet from an emitter to a receiver but with some added checks so that it makes sure the packet always arrives, integraly, in the right order.
This means that if a packet is lost or using a long path, the latency will be greater and the client program will have to wait.

But with UDP, you can add your own routines to check the packet size (in bytes), the packet Id (to determine its order), and to decide when to keep waiting for a traveling packet or when to discard a traveling packet.

The packets may use different paths depending on the network state (some ISP modems may be damaged or full, some phone lines may be damaged), so sometimes i think it is better to discard a traveling packet and to wait for the next packet, or to send a request to the sender for a copy of the packet (which may use a shorter path this time, depending on the network state)

This is why UDP is better for video games which require several packets sent each second.
Now how to manage the update of the world on the server if one or several packets of a client do not arrive in time is another story (i mean a challenge).

I think that instead of trying to code the perfect system to make sure the game runs with computers all over the world connected to only one international server (an thus with a high ping for many users), a better approach is to have several national servers so that the ping is always low for the users (or at least lower).

That's what i have understood so far, but i may be wrong on some points.


BIG BUG(Posted 2013) [#5]
There are some games out there which use TCP instead of UDP.
However the TCP implementation in Blitz3D is a special case. A lag in a TCP connection will not hold only the data back, but your whole game will be stopped until the data has arrived (or a timeout occured).
So anything other than a simple card game should use UDP (or an external library) instead of TCP. You shouldn't use TCP not even as "additional" protocol for chats or something. Simple as that.


Wayne(Posted 2013) [#6]
I've used UDP with B3d, for the following reasons:

1. Unlike TCP UDP is connectionless protocol. So if your using winxp, or win7 the max number of inbound connections is limited to 10, UDP has no limit.

2. UDP is non blocking, and this is ideal as B3D is running on single thread.

3. Using UDP I send position data about 10/sec and it works nicely.


Imperium(Posted 2013) [#7]
You can actually change the number of connections in XP to 100 if you know where to look.

UDP wins.

@Wayne do you have an example you could share?