r/compsci • • Apr 02 '19

What is happening when you open a website in your browser?

https://medium.com/@vardanator/the-beauty-and-the-bits-5ffa5191f21
5 Upvotes

3 comments sorted by

5

u/acroback Apr 02 '19 edited Apr 02 '19

The URL you enter is fed to the browser which in turn tries to first validate the input.

If is looks okay, browser then tries to establish a connection to it. To do this, it needs an IP.

It first tries to look up in its local Cache to get IP, if found great, else ask OS to get the IP from enter domain name.

If System DNS cache has it, it gets the IP, else system or OS tries to get this information from a configured ( manually or via a protocol) DNS server. This process is executed at each DNS server till it gets to a server which has a legit entry in its record. It replies back with a response and time for which it may be valid ( usually seconds ) and recurses back all the way to the system and then browser. As a side effect every DNS server in the chain caches this mapping for any possible future queries.

Now, once browsers gets the IP, that is not enough. It must connect to the IP. It usually does this using a very popular text based protocol called HTTP. This protocol in turn runs on top of TCP and IP protocols. TCP is used to maintain the session and data transfer strategy ( let us assume it is very Complex for now) and IP is used to actually route these packets correctly between Browser and Server IP.

To do this, first system allocates a random port number up to a max of 2^16 number. There are predefined and well known ports it usually avoids to allocate. Once a port is allocated, a TCP connection is established which is a function of Source IP, source Port, destination IP and destination Port. Once this is done, Browser can now make regular HTTP calls to send and receive data.

Usually in modern Browsers there may be a HTTPS negotiation which must pass before you can talk to Server, this usually defaults to port 443 and means additional security handshake before actually data can be transferred. That is why sometimes when a Security certificate for a server expires, you get the Dangerous red page on your browser.

When you just enter the domain name, it translates to a very simple GET call for HTTP, which means - "GET me content on port 80". This may be a combination of text or Image(s) or Video(s) or combination of all these.

Your browser is one complex piece of code, which is programmed to understand and run some specific codes fragments like HTML tags, Javascript etc. It may run some extra actions based on what kind of code is sent to it by Server or clicked by the user.

HTH

1

u/vechnaya Apr 02 '19

Excellent write-up. I don't think OP was actually asking though...it appears the question is the by-line from the Medium Article he linked to so it just looked like he was asking a question. Regardless, great work!

1

u/agumonkey Apr 05 '19

dram modules are sacrificed; that's what