Skip to content

Why opening two port for when connection #4940

Answered by darrachequesne
ezzadaghweb asked this question in Q&A
Discussion options

You must be logged in to vote

The port (found in either socket.request.socket._peername.port or socket.request.socket.remotePort) is the port on the client machine used to establish the TCP connection.

You can check it with netstat on Linux:

io.on("connection", (socket) => {
  console.log("remotePort", socket.request.socket.remotePort); // prints "remotePort 42620"
  console.log("localPort", socket.request.socket.localPort); // prints "localPort 3000"
});
$ netstat -an | grep ":3000"
tcp        0      0 127.0.0.1:42620         127.0.0.1:3000          ESTABLISHED
tcp6       0      0 :::3000                 :::*                    LISTEN     
tcp6       0      0 127.0.0.1:3000          127.0.0.1:42620         ESTABLISHED

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@ezzadaghweb
Comment options

@darrachequesne
Comment options

@ezzadaghweb
Comment options

@darrachequesne
Comment options

Answer selected by ezzadaghweb
@ezzadaghweb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants