开发者

Broadcast listener using Java?

I have a DP(data processor, java code) running in my network and few C clients. Client needs to communicate to the DP for data exchange. Client need to discover 开发者_运维百科the DP using broadcast discovery. Client will broadcast a message to which DP will listen and response for availability. I'm not sure how to add listener in Java for the broadcast messages, I tried using DatagramSocket but it asks for port number? DP should listen to broadcast message received on any port.


Unless clients are using something like ICMP, they do need a port too. In a normal TCP/IP stack broadcast and multicast is done with UDP (yes, that's DatagramSocket in Java-speak), thus a need for the port number. Just pick a port that you like, of make it flexible and provide a configuration option for both the server and the clients.

There are other options of course like DNS SRV records, multicast DNS/Bonjour, custom IP protocols, etc. but those are much harder to deal with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜