But where I am desperate is how to make it work over 'public network' and not only localhost or localnetwork.
When creating server, I can specify to listen on 127.0.0.1, 192.168.x.x, localhost, 0.0.0.0 and then connect with client to the server, but these addresses are not available to public network. I'd like to make client able to connect to my external IP address like "126.96.36.199". I tried to bind server to the external IP but with no luck.
Can it be caused by firewalls or by the fact I am behind a router? Or is it simply not possible using those two classes?
In the end, it doesn't have to be using ServerSocket and Socket at all, but I would be grateful to anyone who tell me how to solve the problem.