Why do we need to specify a port number with an IP address even if we are using HTTP protocol? For example - http://xyz:8080...
- what does this even mean? We alrea
The default port for HTTP is 80 and HTTPS is 443 but port numbers range from 0 to 65535. Most web servers listen on the default port so it's simpler to refer to the URL without the port. For example, http://www.cnn.com/
refers to the same resource as http://www.cnn.com:80/
since port 80 is the default port. If a HTTP/HTTPS service is other than the default port then the port must be specified in the URL.
The URL is defined by RFC 1738 with this simplified syntax which includes the port:
://:/
So for example, the URL http://xyz:8080/...
refers to a host machine name or IP address listening to port 8080 with HTTP as the protocol. The HTTP (or web) server at that address then resolves the url-path to the particular service or file.
The port is optional when it is the default port for the given scheme or protocol (e.g., HTTP=80).
A given machine can host multiple different products with HTTP services from different ports. For example, Apache web server is listening to port 80 on a given server while Apache Tomcat is listening to port 8080 on the same machine. Various database and messaging products typically have HTTP services on different ports. The port is part of the address from which a client can reference a specific service.