Mix TCP and UDP

I want to make a multiplayer game that works on the Internet, and not just with low latency, with high bandwidth, for example with a local network.

There are some network aspects of my game in which UDP is clearly better suited, for example, to transmit information about the positions and speeds of various players. This data should be received as quickly as possible, and re-sending the dropped packets will not help, because by the time the client reaches the client, this data is irrelevant. For some packages, you can opt out.

However, there are other aspects of my game that require a strict order, guaranteed delivery. Automatic fragmentation (tearing and assembling for large pieces of data) packets is also very useful. TCP seems to be doing all this. Data is not at all useful if it is not strictly ordered and there are no missing packages. In some cases, latency will inevitably suffer for this type of data, but it is inevitable.

Thus, instead of implementing TCP-like functions over UDP (with data buffers, marking packets with numbers to determine their order, packet acknowledgment systems), which would be a ton of work to ensure that it works correctly and efficiently, I would just like to use TCP and UDP at the same time.

However, I heard that TCP and UDP can fight each other for bandwidth if you use them together at the same time, and using TCP will increase the speed of dropped UDP packets. It's true? Are there any other problems that I will encounter when mixing these two protocols?

+5
source share
4 answers

If you are having difficulty, I suggest adding an extra layer of abstraction between you and the guts of your network code. Try the multiuser network library, for example " RakNet ".

+1
source
+1

- TCP UDP. , : UDP- TCP, UDP - TCP . , / . , UDP, TCP-, . , .

0

Try iperf and you will see that if one TCP connection for downloading should share a 100 Mbps line with an application downloading UDP download traffic at a speed of 100 Mbps, then you will measure approximately 50 Mbps TCP throughput and receive approximately half the number of UDP packets sent (i.e., UDP drop rate of about 50%).

0
source

All Articles