端口和本地端口有什么区别?

What is the difference between port and localport?

当我在 java 中打印 Socket class 的对象时,它会像这样打印套接字详细信息—— Socket[addr=/127.0.0.1,port=49989,localport=10]。我知道端口 number.But 我不明白为什么有两个端口号(端口和本地端口)?

根据 javadocs

localPort - the local port the socket is bound to, or zero for a system selected free port.

对于其他进程,端口号将为 49989,但此进程将使用端口 10。

想象一下打个电话,你拨的号码是49989,但你的电话号码是10