Reputation: 117
How can I find a java server on the LAN by giving the client only the network part of the IP address? Can I do it this way?
Socket sock = new Socket("10.10.10.*", 4444);
Upvotes: 0
Views: 5062
Reputation: 1857
I had the same problem and here is how I figured it out : UDP Broadcast. It will allow the client to connect to server regardless of its IP, so you don't have to hardcode the IP Address, only the port used for UDP (see below).
Here is how it works :
Here is the tutorial that helped me : http://michieldemey.be/blog/network-discovery-using-udp-broadcast/
Upvotes: 6