简体   繁体   English

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

[英]Testing a client/server Java application on a virtual machine using 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 (ie, the client connects to the server running on localhost ). 我正在测试基于客户端 - 服务器的Java应用程序,其中特定方案涉及客户端和服务器在同一主机上运行(即,客户端连接到在localhost运行的服务器)。 This seems to work fine except for when I test this scenario on a virtual machine (running 32bit Windows 7) using VirtualBox. 除了使用VirtualBox在虚拟机(运行32位Windows 7)上测试此场景时,这似乎工作正常。

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. 令人惊讶的是,我尝试使用putty连接到服务器,并且连接按预期运行。 Both the Java client and putty tried to connect to localhost - the client failed but putty succeeded. Java客户端和putty都尝试连接到localhost - 客户端失败但putty成功。

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 注意 :这与从虚拟机虚拟机寻址localhost不重复

How do you connect to the localhost? 你如何连接到本地主机? By connecting to the hostname "localhost"? 通过连接主机名“localhost”? You could try connecting to the InetAddress returned by getLocalHost() 您可以尝试连接到getLocalHost()返回的InetAddress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM