我有一个在Windows上运行的Java客户端和在Linux (VM)上运行的c++服务器。我正在尝试将客户端连接到服务器。但是我不知道应该使用什么IP地址。 我的虚拟机配置是默认的,我在其中有NAT网络。 以下是从ifconfig获得的内容:
enp0s3 Link encap:Ethernet HWaddr 08:00:27:97:86:ce
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::8651:2c9d:6683:e4fc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:855910 errors:0 dropped:0 overruns:0 frame:0
TX packets:267095 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:940974525 (940.9 MB) TX bytes:24398399 (24.3 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:9710 errors:0 dropped:0 overruns:0 frame:0
TX packets:9710 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:875898 (875.8 KB) TX bytes:875898 (875.8 KB)
这是我从ipconfig获取的信息:
Ethernet adapter Ethernet:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter Połączenie lokalne* 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . : home
Link-local IPv6 Address . . . . . : fe80::ddca:c63d:1b9e:6255%14
IPv4 Address. . . . . . . . . . . : 192.168.1.3
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.254
Ethernet adapter Połączenie sieciowe Bluetooth:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Tunnel adapter Połączenie lokalne* 4:
Connection-specific DNS Suffix . :
IPv6 Address. . . . . . . . . . . : 2001:0:9d38:90d7:10c9:14d5:da7f:e55c
Link-local IPv6 Address . . . . . : fe80::10c9:14d5:da7f:e55c%13
Default Gateway . . . . . . . . . : ::
我尝试使用以下方法进行连接:
socket = new Socket("10.0.2.15", 1236);
当我在虚拟机上使用本地主机客户端时,一切正常。
因此,我认为Windows和虚拟机之间存在连接问题。