I am confused on how requests to websites are received. If I type in 172.217.5.110 to my browser, google.com sends me its home page. I didn't have to specify the port number. How does that work? I read that commands such as ping use ICMP, which does not use port numbers, so I thought maybe that's why. However, I also read that one of the first steps of sending data using HTTP is to establish a TCP connection, which requires a port number. How does the web server listen for requests sent to its IP without a specified port number?
2 Answers
Ports are still involved even if you don't explicitly give them. It is an inherent property of the TCP and UDP protocols that you need port numbers.
If you don't give an explicit port number in the URL the browser uses default port numbers: 80 for http://
and ws://
, 443 for https://
and wss://
, 21 for ftp://
.
In other cases there are fixed port numbers, i.e. the mail server is always at port 25 and the DNS MX record only returns the name but not the port. For other situations (like SIP) there are DNS SRV records which also provide information about the port to use etc.
How does the web server listen for requests sent to its IP without a specified port number?
It doesn't. For typical web servers like nginx or apache one still has to specify the port number to use in the servers configuration. Others might use default port numbers.
-
Ok that makes sense. I have another related question: I'm writing a chat program and I have to specify a port that the servers listen on. How can I be sure that that port is always free? Or does it matter if another program is also listening on that port? Commented Jan 6, 2019 at 8:51
-
@Caders117: This is a completely new question and should not be asked in a comment. Apart from that this is less a question about networkengineering but about programming, i.e. off-topic here and on-topic on stackoverflow.com. But in general the answer is that you simply have to make sure that the port is not used by another application. That's why there are some application specific ports - see iana.org/assignments/service-names-port-numbers/…. The other option is to use just some free port and somehow tell the peer which port to use. Commented Jan 6, 2019 at 11:12
Ports number is mandatory while hosting application in IIS or any web server . Application coding is developed and services and enabled on any of the choosen port
Without port number. it is impossible to host àpplication in webserver . To access application this hosted ports has to be in listening mode . And at network level along the network path the specific port has to be in open stàte .