开发者

Which is best protocol TCP or UDP?

Im going to develop one android application which transfer music file, contact exchange, voice chat, text chat etc.. through WiFi. Which protocol wi开发者_开发知识库ll suit my application UDP or TCP. Because both protocol having some merits and demerits. Can u give me some suggestion, it will helpful for me..

Thanks in advance


If you don't know which is better for your application, then you should use TCP. When you get to understand TCP and its limitations better, then you may want to delve into the arcane world of UDP.


If one was the best (universally), the other wouldn't exist anymore...

If you want to make sure, that the data you send is really delivered correct to the client: use TCP.

If you're application is performance critical and/or bandwith is a limiting factor and the data packages are small (fit in one frame), use UDP.

In your case, I'd use TCP/IP, because for streaming or big data it is necessary that all frames arrive in the correct sequence (or can be ordered by the client).


TCP.

UDP does not provide reliable transfer, which sounds essential for the applications you describe. For example, if you're exchanging contact details and half a phone number isn't received on the other end - which is very possible with UDP, how would you recover from that?


TCP:

This protocol is the most commonly used, the reason for this is its reliability on packet delivery, as each packet is guaranteed to arrive at its destination. its more commonly used for things like streaming media, where you do not wish to have data last/

With TCP, its slightly slower than UDP and has more features:

  • Ordered data transfer - the destination host rearranges according to sequence number
  • Retransmission of lost packets - any cumulative stream not acknowledged is retransmitted
  • Error-free data transfer (The checksum in UDP is optional)
  • Flow control - limits the rate a sender transfers data to guarantee reliable delivery. The Receiver continually hints the sender on how much data can be received (controlled by the sliding window). When the receiving host's buffer fills, the next acknowledgment contains a 0 in the window size, to stop transfer and allow the data in the buffer to be processed.
  • Congestion control

Source @ Wikipeida > Transmission Control Protocol -> Data transfer

TCP would be the most best choice to start of with as its the most comment and has a wider range of features


You should use TCP, since you want to make sure your packets actually arrive.

TCP has a little processing and bandwidth overhead but makes sure your packets really do arrive and resends those which have not been reported to be arrived.

UDP is most commonly used in scenarios where the arrival of all packets is not mission critical, e.g. if you update movement data in an action game like a 1st person shooter. But even then, I'd use TCP these days.


The application you are talking about has a large spectrum of requirements in terms of networking. You might want to consider using:

  • TCP: for the delay tolerant needs e.g. non-realtime file/message transfer
  • UDP: for delay intolerant needs e.g. voice

With TCP, retransmission is built-in that which you don't get with UDP. You don't want to be retransmitting voice packets (as example).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜