我在计算机(1个服务器和2个客户端)中尝试了带有服务器和客户端的异步套接字:
server ip = 0.0.0.0
client 1 ip = 127.0.0.1
client 2 ip = 127.0.0.2
在服务器端,当服务器从第一个客户端接收到第一个连接请求时,我将第一个客户端套接字存储在一个 ArrayList 中。使用以下代码,我得到一个客户端 ip 是 127.0.0.1
TryCast (tcp.Client.RemoteEndPoint, IPEndPoint).Address
当服务器从第二个客户端收到第二个连接请求时,我得到一个客户端 ip 是 127.0.0.1 但不是 127.0.0.2
我将上面的代码从RemoteEndPoint更改为LocalEndPoint输出是正确的。为什么服务器端的RemoteEndPoint不代表客户端 IP?
从
TryCast (tcp.Client.RemoteEndPoint, IPEndPoint).Address '(second client ip not correct)
至
TryCast (tcp.Client.LocalEndPoint, IPEndPoint).Address ' (correct result)
谢谢。