0

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?

3

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? – Caders117 Jan 6 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. – Steffen Ullrich Jan 6 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.