3

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

Community
  • 1
  • 1
Dawood
  • 5,106
  • 4
  • 23
  • 27
  • Can you telnet to the service using localhost and port? Can you connect if you use the hostname instead of localhost? – Peter Lawrey Jan 29 '12 at 08:50
  • 2
    I guess it is IPV4 and IPV6 issue, i would suggest try by IP than using localhost. – kosa Jan 29 '12 at 08:51
  • @thinksteep, to be more specificy, I'd say try `127.0.0.1`. This reminds me when that even didn't work on Android and one had to use some special IP to do communicate with the localhost during development. – Muhammad Gelbana Jul 27 '12 at 09:47

1 Answers1

0

How do you connect to the localhost? By connecting to the hostname "localhost"? You could try connecting to the InetAddress returned by getLocalHost()

Mads Nielsen
  • 634
  • 5
  • 16