Jonathan
Jonathan

Reputation: 3034

Can sending first a UDP message and then a TCP message be any good?

I have an application that communicates in real time with other clients over LAN. The application requires packets to be in order and all to arrive. It also requires as fast transfer as possible and I seem to have some problems with TCP in this matter.

So I was thinking about this, as a non-experienced network programmer, what if I first send a UDP protocoled message and then the same data with TCP. If the UDP-message arrive I will have it as fast as possible if not I still have the TCP message that will make sure I'll atleast get the packet. Obviously I'll make sure that I don't read the same data twice by giving each message an ID or similar.

Is this any good approach? I was thinking that maybe sending the tcpmessage simultaneously will just slow the udp message down so It wont make a difference anyways.

Upvotes: 0

Views: 628

Answers (3)

Science_Fiction
Science_Fiction

Reputation: 3433

UDP has very specific use cases. i.e. say an online game which sends a players co-ordinates. You state the order and acknowledgment is needed, therefore TCP seems like the most sensible approach.

Although just to put a twist in the mix, TCP can sometimes surprise you and be better performance wise under specific circumstances.

TCP will try and buffer the data before it sends it across the network (more efficient use of bandwidth). UDP on the other hand puts a packet across the network immediately.

Now imagine writing lots of small packets across a network, UDP may cause congestion whereas TCP is better controlled.

Upvotes: 1

av501
av501

Reputation: 6729

No it is not a good approach at all. You will have now twice the data being sent. For real time communication UDP is the best approach. You should design your reciever algorithm to manage out of data arrival and sort it and also non arrival of some data.

Also the kind of data being sent can be a deciding factor. If its transactions of a financial kind, udp is not a good idea. But then you should be on a different network.

If it is video data, real time is very important, losses can be tolerated.

So see if you can use the properties of your data to manage udp connection well.

Upvotes: 1

user82238
user82238

Reputation:

No, this is not a good approach.

You are doubling your network bandwidth and significantly increasing the complexity of your networking code for very little gain.

TCP and UDP have very different characeristics. If you care about data arriving in a timely manner, where if data is late it is no use, then TCP is not useful and as such you should use and only use UDP. If you do not care about data arriving in a timely manner, then UDP is not useful, as it is not reliable.

Upvotes: 2

Related Questions