Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to specify a port number while using HTTP protocol?

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 already know that while using HTTP the request will be served at port 80, so why do we specify a port explicitly?

like image 696
unmesh_swar Avatar asked Jun 16 '18 13:06

unmesh_swar


People also ask

Why does HTTP need a port?

HTTPS Port 443 (TCP) - This is the port that you access on a server when you go to a web address that starts with https:// rather than just http:// . It uses Transport Layer Security (TLS) technology to ensure that information transmitted while connected is kept secure.

Why do we need to specify the ports when sending data?

When clients attempt to connect to your server they need your computer's IP address, but they also need to indicate which service they want to communicate with, so that the data is sent to the appropriate application. The port number serves to uniquely identify that service on a particular host.

Which is the port number used for HTTP?

By default, these two protocols are on their standard port number of 80 for HTTP and 443 for HTTPS.


2 Answers

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, https://www.cnn.com/ refers to the same resource as https://www.cnn.com:443/ since port 443 is the default port.

If an 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:

<scheme>://<host>:<port>/<url-path>

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.

like image 57
CodeMonkey Avatar answered Oct 04 '22 08:10

CodeMonkey


A port is like a "channel" in a way... If you have to access different functions of the same website, you use different ports. HTTP is port 80, HTTPS is 443, SSH is 22, and so on.

like image 41
Simon Avatar answered Oct 04 '22 08:10

Simon