What is localhost:8080 ?


👤 Diwas Poudel    🕒 03 Oct 2022    📁 TECH

What is localhost:8080?

Everything connected to the internet can be found using a socket address. Socket Addresses are a combination of IP addresses (or simply hostname) and port numbers. Socket Addresses are used to identify both machine and the service within the machine. If we consider localhost:8080 then here localhost is the hostname which is bound to the IP address ie. 127.0.0.1 by default and 8080 is the port. Here, localhost means this computer ie. the computer which you are using right now.

localhost-and-8080-port
fig. socket address is a combination of a hostname(or IP address) and port number

Ip address is just like a house address which finds the right house. Similarly, Ip finds a particular system in a network.

Port is the person's number. Person number which finds an actual person on that house. Similarly, Post is used to identify the process that needs to consume the packet.

In localhost:8080, localhost is a DNS hostname that is pointing to the localhost IP address ie. 127.0.0.1. If you type ping localhost in terminal or command prompt, you will find that your machine automatically points localhost to IP addresses such as :1 or 127.0.0.1. Actually, 127.0.0.1 is the IPV4 address and::1 is the IPV4 address of localhost.So typing localhost:8080 or 127:0:0:1::8080 are same things. Here 127:0:0:1 is a private Ip address that is not recognizable by another computer in the network. It is recognized by this machine only.

Generally while building the application locally by the web developer, they develop the web application and the default socket will be localhost:8080. This is the default port that the webserver XAMP, WAMP, and LAMP server uses for developing and testing the application.8080 is just a random port someone sets in different web servers for testing and development and you can change it if you want.

Also read: Difference between Post 80 and Port 8080

But note that no two applications or processes can use the same port. ie. two applications running cannot run on port 8080 at the same time. If one process is using 8080 then if another application tries to access 8080 then it will give you a message like "port is already in used" please use another port.

If you are running a .net application or PHP application and when you are debugging that application it will have localhost:8080 upon running in the browser URL by default. The web server will not search the information on the internet but will search pages in a local hard drive it will search for the webpage by local webserver at port 8080 from the local hard drive

If you are using a windows machine, then the IIS server is enabled then just typing localhost will redirect you to C:/inetpub/wwwroot/iisstart.htm files. Here the port by default is 80. Considering the C drive is your OS drive.

Similarly, if you use the XAMP server then typing localhost will just find the content like index.html or index.php present in htdocs folder.

URL Syntax : {scheme}://{hostname}:{port}{path} then for localhost:8080 , {scheme} is "http" , {hostname} is "localhost", {port} is 8080 and {path} is "/"

What is an 8080 port?

It is to be noted that there is a total of 65,535 ports for communication between the devices where 0-1023 are well-known reserved ports you cannot assign IP to this. Port 1024 to 49151 are user ports and users can assign applications to them. And port above 49151 is a private port. So, port 8080 is the user-registered port. In our case by default XAMP or WAMP server assign for the application.

If you have a web server already running on default port 80 and you like to host another web server on the HTTP service then the web server will automatically host you to port 8080 which is a best practice followed by most web servers and if that port is also in use then may assign any user port like 8081,8082 etc

You can change it, the only thing you have to keep in mind is that you cannot assign an already used port otherwise it will give an error as we have mentioned earlier.

Also read: Computer | Laptop Ports and Their Functions Explained

8080 must be explicitly specified for HTTP as 80 will be assumed by most browsers. But some web server like Angular, and Rails server uses 8000, 4200 as the default port 

What exactly is going on When I type localhost:8080?

Ans: When you type localhost:8080, this will make your web browser ask your operating system to do a DNS lookup and resolve the hostname as localhost.

The operating system looks at the files for DNS lookup.

In the windows system, the DNS mapping is located inside the host's file located inside the %systemroot%\System32\Drivers\Etc path and the host's file looks like this:

127.0.0.1       localhost
 ::1                 localhost
windows-etc-hosts-file
fig. localhost mapping to 127.0.0.1

In Unix systems like Linux, the DNS mapping is stored inside /etc/hosts file, and looks like this:

127.0.0.1   localhost
::1     localhost ip6-localhost ip6-loopback
linux-etc-hosts-file
fig. mapping localhost to 127.0.0.1

So when you hit localhost:8080 the browser then the webserver finally gets the result from the 127.0.0.0:8080 location and displays the result in the browser.

FAQ:

Do localhost:8080 and 127.0.0.1:8080 connect to the same IP address?

Ans: Yes both localhost:8080 and 127.0.0.1:8080 point to the same IP address on TCP port 8080.

Is localhost:8080 is equivalent to 127.0.0.1:8080 ?

Yes.They are equivalent.So, typing localhost:80/test is equal to 127.0.0.1:80/test

How to Change XAMPP Apache localhost port from 80 to 8080?

Sometimes port 80 is already in use; in this case, try using the 8080 port in Xamp. Let's look at how to change it.

  1. Open xampp
  2. Right-click on the Config button for Apache.
  3. Click on Apache(httpd.conf) file.
  4. Find the Listening port and change the port from 80 to 8080.
    ie Listen 80 to Listen 8080
  5. Also, change ServerName from localhost:80 to ServerName localhost:8080
  6. Then save the file and after that restart Xamp and by default, your Apache server will run on port 8080
Also read: What is USB upstream/downstream port on the monitor?

Conclusion:

When you run a web server on your local computer, you will have to connect a web application with the web server and port 80 is already in use, so you will need to use a new port. So, most of the web server usage available port 8080 to connect the application which is currently running. If port 8080 is already in use by some other process then the web server may assign 8081 for the application.