Now that I am playing with the ESP8266, I need to understand some concepts which I never dealt with before. The internet, amongst all the technologies that have evolved in the last few decades, seems to be alone in having never been made simpler.
So, when I formulate an AT command for the ESP8266 to connect to a server, the command looks like
The final parameter in the command is a port number. Now is that port something specified at the server end, or does that represent a port specified for my router? I can scan for ports of a particular server using the built-in MAC Network Utility, and it generally shows a long list of ports, some which are open, all others with some designators. So when making a connection, can I use any open port?
But in very simple terms if you think of the IP address as being the town, street and house number for your address then the port is the room number within your house. Some ports have special uses but I can't remember the details.
Think of the IP address as the phone number of a business and the "port" is the extension to connect to someone in the business. That comes close to approximating what a "port" is in the network world. Also recognize that there are a bunch of pre-defined ports in common use for things like FTP, HTTP (80) etc. It is also important to understand in the network scheme of things that many ISP's will block certain ports to prevent things like you having a server on your home network that is available to the outside world. Many people don't realize this and can't figure out why they can't talk across the network to some server or another on their home network even if port forwarding is enabled.
I don't see anything wrong with any of the previous answers but here's my non-expert input.
In general terms a port is where something goes in, or out, or both. There are several analogies in the previous posts.
As far as the specific use in networking goes here's a simplified explanation that I hope is reasonably correct.
The server sends information to your 'public' IP address and a previously agreed upon port number. The IP address is sufficient to get the information to your router and the router, if it has been configured properly, uses the port number to send the information to the proper device on the 'private' side of your network.
Each router manufacturer has a somewhat different technique for doing the configuration which makes it difficult to provide generic instructions. In general you have to instruct the router to accept packets directed to a specific port and then tell it which 'private' IP address and port number to send those packets to.
In my case the incoming (public side) port numbers and the port number at the actual device do not have to match but I don't know if that is always the case. This capability allows one to bypass any ports that might be blocked by the ISP since I you can just use a non-blocked port number on the public (ISP) side and have the router fix things up on your side.