Tcp – Difference between UDP and TCP

ipv4layer4tcpudp

http://www.dummies.com/how-to/content/the-tcpip-networking-protocol-suite.html

I was reading the difference between the two, and in the example of TCP:

For example, when a user running a Web browser requests a page, the browser uses HTTP to send a request via TCP to the Web server. When the Web server receives the request, it uses HTTP to send the requested Web page back to the browser, again via TCP.

Example of UDP:

The best-known Application layer protocol that uses UDP is DNS, the Domain Name System. When an application needs to access a domain name such as www.dummies.com, DNS sends a UDP packet to a DNS server to look up the domain. When the server finds the domain, it returns the domain's IP address in another UDP packet.

Which of the two happens initially? How does connection to a website happens in the end?

Best Answer

I'll try to answer your question directly without going into a huge rant about TCP v UDP.

Basically you need to understand that both HTTP and DNS are completely independent applications/protocols. Sometimes you need to actually send a DNS query to a DNS server, sometimes you don't (if the DNS record is cached locally on your PC/Server).

  1. We do NOT have a DNS record cached.

    • http://google.com is entered in the browser.
    • Your PC checks the local DNS cache, and sees it does NOT have a record for google.com
    • A UDP DNS query is sent to a DNS server, in this case it's most likely your ISP's DNS server.
    • The DNS server sends a UDP response back.
    • You now have your answer in the form of an IP address, now you can initiate your TCP connection to google.com
    • The 3-way handshake occurs between you and google.com (SYN, SYN/ACK, ACK) - if you do not know what this is you can search for "TCP 3 way handshake" and find some good information.
    • After the handshake completes, HTTP will render in the form of your favorite search engine.
  2. We HAVE a DNS record cached. There is a very small difference here, but I'm going to include the whole thing so you can see the comparison.

    • http://google.com is entered in the browser.
    • Your PC checks the local DNS cache, and sees it has a record cached in the form of an IP address.
    • You now have your IP address for google.com, now you can initiate your TCP connection to google.com
    • The 3-way handshake occurs between you and google.com (SYN, SYN/ACK, ACK)
    • After the handshake completes, HTTP will render in the form of your favorite search engine.

So just because you're trying to get to a webpage you do not have to send a UDP DNS query. DNS is independent, visiting a webpage is not the only time you'd need to use DNS. Feel free to comment if you need clarification.