The unstable release of Debian is of course tricky in a lot of cases, so there is also a little stumbling stone on your path of Java network programming. On every new system it annoys me.
Before I wrongful blame my preferred Debian release called Sid I have to acknowledge I don’t know whether this feature is also available in other releases… Here is a small program to test/reproduce:
Compilation shouldn’t fail, but if you try to launch it you’ll get an exception like that:
This is caused by one little line in /etc/sysctl.d/bindv6only.conf saying you want to explicitly bind via IPv6. But my connection (maybe yours too) communicates still over IPv4, so this method of networking of course fails. To change this behavior you have to choose between two solutions.
Solution 1: Permanent modification (needs to be root)
You can change this behavior for the whole system by editing the file /etc/sysctl.d/bindv6only.conf :
After that just type invoke-rc.d procps restart in your terminal to let your changes take effect. Your next run should work fine.
Solution 2: Change it for this single example
If your are not allowed to change system settings, you can add -Djava.net.preferIPv4Stack=true to your execution command:
This causes your actual runtime to connect the network via IPv4, no matter to system preferences. I hope this could save some time of developers like me ;-)