使用 VirtualBox 在虚拟机上测试客户端/服务器 Java 应用程序

发布于 2024-12-29 14:19:27 字数 524 浏览 3 评论 0原文

我正在测试一个基于客户端-服务器的 Java 应用程序,其中特定场景涉及让客户端和服务器在同一主机上运行(即客户端连接到在 localhost 上运行的服务器)。这似乎工作正常,除非我使用 VirtualBox 在虚拟机(运行 32 位 Windows 7)上测试此场景。

注意:此后的一切都在虚拟机内运行。我启动服务器并尝试使用客户端连接到它,但连接超时。令人惊讶的是,我尝试使用 putty 连接到服务器,并且连接的行为符合预期。 Java 客户端和 putty 都尝试连接到 localhost - 客户端失败,但 putty 成功。

有谁对为什么会发生这种情况有可能的解释?

注意:这不是 Addressing localhost from virtualbox 虚拟机

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沦落红尘 2025-01-05 14:19:27

你如何连接到本地主机?通过连接到主机名“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()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文