I wrote a Client/Server app in java using TCP connection. For the Client to run I need to provide it with IP of the server. It works well on two consoles on one Windows with IP = localhost, but not on two VBoxes with linux on them. I tried checking what’s the IP of VM with
ifconfig but it just shows 127.0.0.1 and this doesn’t work. Should I change some network settings of the VMs or look for other IP? The error that I’m getting when I try to run Client with IP = 127.0.0.1 is “Connection refused”. What should I do?
127.0.0.1 is the localhost or loopback address. It always means the local machine (thus, localhost). So if you have VB1 and VB2 virtualbox systems, VB1’s 127.0.0.1 will point to VB1, and VB2’s will point to VB2. If ‘ifconfig’ only shows 127.0.0.1 then your network interface is not connected to your LAN — either physical or virtual.
Put another way: if you run the server and client both on the same virtual machine (or physical), 127.0.0.1 will be fine. If they are two different hosts on the network, it will not communicate between them.
You need to make sure their network interfaces are configured as a method where they share a subnet. I typically use “Bridged” so the VB hosts are effectively their own machines on my physical network. You can review the options here.
Then you need to use ifconfig on the server host to get the IP address for the client to connect to.
Also don’t forget to check firewall settings on both machines.