Network discovery in Java Multicast/Broadcast Java

流过昼夜 提交于 2019-11-29 08:58:16

I had a similar problem a long time ago and I resolved it as follows:

  • The server broadcasts a UDP packet on the network to 255.255.255.255
  • All reachable clients will respond with a UDP packet that include their IP and any other information you wish to send.

The packet I personally used looks like

public class UDPDiscoveryPacket{
      public final long sendingTime;
      public final String clientIP;
      public UDPDiscoveryPacket(long sendingTime, String clientIP){
         this.sendingTime = sendingTime;
         this.clientIP = clientIP;
      }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!