When you type "localhost" into the browser, it calls the operating system to resolve that name to an IP address and the O/S will go on and take a peek at /etc/hosts before it starts talking to DNS servers ...
For localhost, it'll always find it in etc/hosts as this a standard entry. In general, if it doesn't find an entry in etc/hosts, it'll do a DNS query to a DNS server.
When you run Node though, ifconfig will give you a list of network interfaces, lo0 (local) lists 127..... and another on en0, by default Node will listen in on all of these IP addresses.
When you type in "localhost:8000" into the address bar, the browser will turn that into a number (IP Address) (domain name part not the route stuff meaning the part before the slash part)
Once the browser has the IP Address, 127.0.0.1:8000 will establish a TCP connection to that IP address and that port number. The destination port will be 8000. Opening up a TCP connection to that IP Address and Port. Once it sets up the TCP connection, it will send an HTTP request over that TCP connection. HTTP GET with whatever you put after the slash so Node will be receving that.
Image: NASA, Public Domain
Post a Comment
Note: Only a member of this blog may post a comment.