6

I was configuring IPtable yesterday. My colleague just asked me this question, and I couldn't anwser. I realized that I'm a much better developper than sysadmin and need to improve that.

So what are they? What are they for? Cons/Pros (if it's relevant).

Kimvais
  • 38,306
  • 16
  • 108
  • 142
Bite code
  • 578,959
  • 113
  • 301
  • 329

6 Answers6

10

These are like basic questions.

UDP :: User Datagram Protocol

1) No end to end Connection between to machines (may be in local network or somewhere in the internet).

2) The data received at the receiver end is not in stream as in TCP but as a complete block of data.

3) At the transport layer no packet order check is performed. That is in case of any error in the received packet, the receiver will not ask for resending the same packet to the sender.

4) Because of the above behaviour no sending buffers are required at the sender's end.

5) As no end to end connection is estld. and there are no handshakings required, UDP are pretty much faster but less reliable than TCP. Thus mostly used in gaming and DNS etc..

6) No acknowledgement required to be sent after recieiving packets.

TCP :: Transmission control Protocol

1) End to end Connection is maintained between to machines (may be in local network or somewhere in the internet).

2) The data received at the receiver end is a stream in TCP. Thus, when we do network programming for servers we first parse the header first and then depending upon the size mentioned in the header we obtain that much more number of bytes from the buffer.

3) Error checking and sequence number are all done. Thus in case any packet is received out of order (rarely) or is erred than that packet is made to resend. Also, lots of other protocols are involved for flow control (end to end flow control).

4) As connection establishment , handshaking and acknowledgement is to be done TCP are basically slower in operation than UDP.(Not significantly I believe)

5) Lots of protocols uses TCP as underlying transport protocol. HTTP,FTP,TELNET etc..

6) The communication procedure involves:

Server:: 1) Socket Open 2) Socket Bind 3) Socket Listen 4) Socket Accept 5) Socket Send/Recv Client :: 1) Socket Open 2) Socket Connect 3) Socket Send/Recv

There are lots of other differeces also..but the above being the most common ones.

Arunmu
  • 6,837
  • 1
  • 24
  • 46
5

TCP is a reliable protocol which ensures that your packets reach their destination and is used in applications where all data must me trasfered accurately between parties. TCP requires both parties to negotiate a connection before data transfer can start and it is a resilient protocol since it will repeatedly resend a packet until that packet is received by the intended recipient.

UDP is unreliable in a sense that it allows some packets to be lost in transit. Some applications of UDP are found in movie streaming where you can actually afford to lose a frame and not jeopardize movie quality. UDP does not need binding between the two parties and is often looked at as a light alternative to TCP.

A nice table is found here:TCP vs UDP

Pepe
  • 6,360
  • 5
  • 27
  • 29
2

P.R.'s answer is mostly correct, but incomplete.

TCP is a reliable, connected stream protocol. Its view of data is that of a bidirectional stream of bytes between hosts: whatever bytes you send will arrive at the other end in the same order, at least as far as the application is concerned (the OS will rearrange packets if needed).

UDP is an unconnected datagram protocol. Its view of data is that of discrete datagrams, or messages, with no guarantee that these messages actually reach their recipient, or that they arrive in the order they were sent. It does guarantee that if a message arrives, it arrives in its entirety and without modification.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
1

There are loads of helpful comparisons

chris
  • 3,986
  • 1
  • 26
  • 32
1

This website probably offers the simplest explanation to the actual difference of UDP and TCP. From implementation point of view, see this question.

For short answer: TCP works kind of like registered letter when UDP is kind of like ordinary letter - with the latter you never know whether the recipient got the packet you sent.

Community
  • 1
  • 1
Kimvais
  • 38,306
  • 16
  • 108
  • 142
0

chris is right! One fancy link dropping out of google is: http://www.skullbox.net/tcpudp.php

fausto
  • 67
  • 3
  • 1
    No he is not. Please read SO rules before making such statments. Discussions on what to do, and what no to do are discussed on Meta SO, and 'look for anwsers on google' have no added value and are not welcome on this website : http://meta.stackexchange.com/questions/76195/how-to-deal-with-have-you-tried-google-comments – Bite code Feb 03 '11 at 09:49
  • @e-satis: I don't think my answer qualifies as "Have you tried Google?". I linked relevant documents, I just didn't copy-paste the contents into SO. – chris Feb 03 '11 at 15:29
  • @e-satis: OK I see your point, but there were some relevant links behind my and chris answers. The content of these links may help. Evidently we were lazy since we could have elaborated (compressed) the contents we found and reformulated them here. I apologize for this and see that answering a so broadly formulated question is probably not the right place here. – fausto Feb 04 '11 at 08:19