This Java application demonstrates how to implement server broadcasting using UDP to announce the server's presence on the local area network (LAN) along with its LAN IP address.
- Server application broadcasts its presence on the LAN using UDP.
- Client application listens for broadcast messages and discovers available servers on the LAN.
- Server IP address displayed in the broadcast message is the LAN IP address.
- Java Development Kit (JDK) installed on your system.
- Basic understanding of Java programming.
- Compile the
Server.javafile:javac Server.java. - Run the server application:
java Server. - The server will start listening for connections on port 1234 and broadcast its presence on the LAN.
- Compile the
Client.javafile:javac Client.java. - Run the client application:
java Client. - The client will listen for broadcast messages and display the discovered servers along with their LAN IP addresses.
- The server broadcasting functionality uses UDP broadcasting to announce its presence.
- The LAN IP address of the server is determined dynamically using the
NetworkInterfaceclass. - You may need to turn off your firewall.