Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any problems with using TCP and UDP in the same application?

The point of my question is to ask if it is accepted to use both TCP and UDP to communicate between client and server.

I am making a real-time client server game with parts of the communication that need to be guaranteed (logging in, etc..), but other parts will be ok to lose packets (state updates, etc). So, I would like to use UDP for most of the data communication but I do not want to have to implement my own framework to insure that my control communication (logging in) is guaranteed.

So, would it be reasonable to initially use TCP to manage a connection, and then on a separate port send data communication pack and forth?

like image 836
Nick Banks Avatar asked Apr 08 '11 19:04

Nick Banks


People also ask

Can an application use both TCP and UDP?

Both TCP and UDP protocols use ports. You can have an application running on a computer using TCP port 80 and another application using UDP port 80. An application address is effectively: IP address + protocol (TCP or UDP) + port number.

Which protocol should use between TCP and UDP for different applications?

TCP is used by HTTP, HTTPs, FTP, SMTP and Telnet. UDP is used by DNS, DHCP, TFTP, SNMP, RIP, and VoIP. The TCP connection is a byte stream. UDP connection is message stream.

Why Many applications are better suited for UDP than TCP?

Thus UDP does not introduce any delay to establish a connection. This is probably the principle reason why DNS runs over UDP rather than TCP -- DNS would be much slower if it ran over TCP. HTTP uses TCP rather than UDP, since reliability is critical for Web pages with text.

What are examples of TCP and UDP in real life scenario?

Most of the online games we play use the services of User Datagram Protocol. Since any amount of delay cannot be tolerated in online games UDP is widely used over TCP which is quite slower. UDP doesn't retransmit the lost data and is a connectionless protocol due to which it is much faster.

Should I use TCP or UDP for my application?

Typically, applications that transfer data files will use TCP since the protocol’s latency and performance issues are not that critical. UDP benefits applications that need to receive data quickly even if accuracy suffers.

What is TCP/UDP?

User datagram protocol (UDP) TCP is a connection-oriented protocol. Connection-orientation means that the communicating devices should establish a connection before transmitting data and should close the connection after transmitting the data. UDP is the Datagram oriented protocol.

Why is TCP more reliable than UDP?

TCP is reliable as it guarantees the delivery of data to the destination router. The delivery of data to the destination cannot be guaranteed in UDP. TCP provides extensive error-checking mechanisms. It is because it provides flow control and acknowledgment of data.

What is the difference between UDP and TCP packet loss?

It results in packet loss for UDP due to contention between the two protocols - remember that UDP is not guaranteed delivery, while TCP is. More TCP packets will get through while UDP suffers - TCP induces UDP packet loss.


2 Answers

You should absolutely do it that way (use TCP and UDP to accomplish different communication tasks.) And you don't even have to use two different ports. One will suffice. You can listen to the two different protocols on the same port.

like image 184
Paul Sasik Avatar answered Sep 22 '22 18:09

Paul Sasik


It is quite reasonable and already used in mainstream. Even when browsing the Web, DNS operations are UDP-based and HTTP connections are TCP-based.

Keep in mind that you should either consider the two connection types to be completely independent or employ additional measures to properly handle any inter-dependencies. TCP connections can have timing issues at the OS and network levels and UDP connections have packet loss issues. You should take specific measures to avoid deadlocks and performance problems when the TCP part of your application stalls or a UDP packet is lost.

like image 35
thkala Avatar answered Sep 22 '22 18:09

thkala