0

so when I run node apps in my VSCode IDE, much of the code I wrote (from a book) has the program "listen on port 3000," and I go to localhost:3000 (which 8080, whichever). However, when I go to a real website, like superuser.com, is my computer listening on it's own port X, or another computer's port X? Another website's port X?

1
  • 2
    It’s not listening on anything, using networking terminology. It’s connecting to another machine. Commented Jul 15, 2019 at 5:54

2 Answers 2

1

I think you may have some confuse in this subject. Let's clarify the options:

  1. When you develop an App that listing to port, you became "server", in that case your App is ask from OS to get all data from specific port, then your PC is listing to that port. In your case when you running service on port 3000, so you get localhost:3000, in that case you are actually listing to this port.
  2. When you visit at superuser.com, the server of superuser.com is listing to port 443 (https) and waiting to clients ( like you ) and open socket to communicate.

In every case you request/send data to any port, in most cases you waiting to reply, so in most of protocols you using random port, and listing to reply. (Since you must make the request from some port..)

1

However, when I go to a real website, like superuser.com, is my computer listening on it's own port X, or another computer's port X? Another website's port X?

When you connect to superuser.com:80, your computer indeed sends the packets from its own port X, and expects to receive reply packets to its own port X. (The port number is randomly assigned for each connection.)

So the packets look like:

computer:X --> superuser.com:80   TCP SYN
superuser.com:80 --> computer:X   TCP SYN <ack>
computer:X --> superuser.com:80   TCP data (HTTP request)
superuser.com:80 --> computer:X   TCP data (HTTP response)

However, that is not the same as "listening on a port" in the sense of accepting new connections. The port X is used strictly for that outgoing connection only – nothing can connect to it from outside.

(In fact, as long as you have VSCode actually listening on port 3000, it is considered "busy" and the OS will never use the same port 3000 for outgoing connections. It's always one or the other.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .