虚拟机的TCP-Socket IP地址
我想在我的Windows电脑和一个Linux虚拟机之间建立套接字通信。Windows机器是服务器。我写了一个C++程序在Windows上设置服务器,还有一个Python程序在虚拟机上设置客户端,但我该怎么连接它们呢?我使用的是 SOCK_STREAM
和 AF_INET
,所以我需要一个端口号和IP地址来连接到服务器。我只是想知道我应该使用哪个IP地址,因为用IPv4连接时没有成功,这是不是因为IP地址不对,还是我的程序有错误?
编辑1:抱歉信息不够详细:
我使用的是Oracle VirtualBox,网络配置设置为默认的NAT。当我在主机(Windows)的命令行中运行ipconfig时,得到了多个IP地址:
Windows IP Configuration Wireless LAN adapter Wireless Network Connection: Media State . . . . . . . . . . . : * Connection-specific DNS Suffix . : * Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : ******** Link-local IPv6 Address . . . . . : * IPv4 Address. . . . . . . . . . . : * Subnet Mask . . . . . . . . . . . : * Default Gateway . . . . . . . . . : * **Ethernet adapter VirtualBox Host-Only Network: Connection-specific DNS Suffix . :* Link-local IPv6 Address . . . . . : * Autoconfiguration IPv4 Address. . : * Subnet Mask . . . . . . . . . . . : '* Default Gateway . . . . . . . . . :*** Tunnel adapter isatap.{*}: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter 6TO4 Adapter: Connection-specific DNS Suffix . : ******** IPv6 Address. . . . . . . . . . . : * Default Gateway . . . . . . . . . : Tunnel adapter isatap.{5289AB9F-2C9F-4CBE-B826-149B3CFBB45F}: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . :* Tunnel adapter isatap.******: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : ******* Tunnel adapter Teredo Tunneling Pseudo-Interface: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . :*
我倾向于认为“以太网适配器 VirtualBox Host-Only Network”下的IPv6地址是正确的。我尝试过ping LAN地址和VirtualBox的host-only网络地址,它们都能得到回应。我也在终端中尝试过traceroute,但这两个都不行。有什么想法吗?
1 个回答
0
我使用“以太网适配器本地连接,链路到链路的IPv6”建立了一个套接字连接。在了解了NAT(网络地址转换)之后,我觉得这很有道理!