使用 VirtualBox 在虚拟机上测试客户端/服务器 Java 应用程序
我正在测试一个基于客户端-服务器的 Java 应用程序,其中特定场景涉及让客户端和服务器在同一主机上运行(即客户端连接到在 localhost
上运行的服务器)。这似乎工作正常,除非我使用 VirtualBox 在虚拟机(运行 32 位 Windows 7)上测试此场景。
注意:此后的一切都在虚拟机内运行。我启动服务器并尝试使用客户端连接到它,但连接超时。令人惊讶的是,我尝试使用 putty 连接到服务器,并且连接的行为符合预期。 Java 客户端和 putty 都尝试连接到 localhost - 客户端失败,但 putty 成功。
有谁对为什么会发生这种情况有可能的解释?
I'm testing a client-server based Java application where a specific scenario involves having both the client and server running on the same host (i.e., the client connects to the server running on localhost
). This seems to work fine except for when I test this scenario on a virtual machine (running 32bit Windows 7) using VirtualBox.
Note: Everything henceforth is running inside the virtual machine. I start the server and try to connect to it using the client but the connection times out. Surprisingly, I tried connecting to the server using putty and the connection behaved as expected. Both the Java client and putty tried to connect to localhost
- the client failed but putty succeeded.
Does anyone have a possible explanation for why this might be happening?
Note: This is not a duplicate of Addressing localhost from a virtualbox virtual machine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你如何连接到本地主机?通过连接到主机名“localhost”?您可以尝试连接到 getLocalHost()
How do you connect to the localhost? By connecting to the hostname "localhost"? You could try connecting to the
InetAddress
returned by getLocalHost()