MangoAutomation / BACnet4J

BACnet/IP stack written in Java. Forked from http://sourceforge.net/projects/bacnet4j/
GNU General Public License v3.0
183 stars 110 forks source link

Use shared socket for IpNetwork #88

Open MertCingoz opened 10 months ago

envas commented 9 months ago

What is the motivation for using MulticastSocket instead a plain DatagramSocket? I assume it is to add multicasting as an alternative to BBMD. In this case your code is not complete and requires a lot of refactoring in Bacnet4J!

  1. To receive data from a MulticastSocket, you must first join a multicast group. The group must be in range from 224.0.0.0 to 239.255.255.255, inclusive. The address 224.0.0.0 is reserved and should not be used. If the address that you try to join is not a multicast address, the joinGroup( ) method throws an IOException. The parameter multicastGroupAddress should be passed to the IpNetwork constructor or NetworkBuilder in case the user is going to configure multicasting.
exclusiveSocket =  new MulticastSocket(localBindAddressStr);
InetAddress group=InetAddress.getByName(multicastGroupAddress);   
socket.joinGroup(group);
  1. The MulticastSocket class adds an overloaded variant of the send( ) method that lets you provide a value for the Time-To-Live field ttl. By default, the send( ) method uses a TTL of 1 and such packets are dropped by routers like other UDP packets (when a packet is received on a router interface, one of the very first things that happens is decrementing the TTL. If the TTL is 0 at this point, the router drops the packet with no further processing. This is a very low-level process and occurs before any other kind of packet processing takes place). Only multicast packets with a TTL greater than the 1 are forwarded. Sending packets via old Bacnet4J send() method means, that packets don't travel outside the local subnet and multicasting is unusable.

Multicast generally makes the configuration of a Bacnet network very complicated.

  1. You cannot have simultaneous devices configured for broadcast and multicast on the same network segment.

  2. Multicast is generally considered to be a low-security type of communication (basically, it is never clear who is receiving the packets sent) and therefore many site administrators prohibit multicast.

Personally, I would see the proper implementation of BBMD and FDT in Bacnet4J rather than multicast.