Host constructor
- {String name,
- int multicastPort,
- IPVersion ipVersion,
- DeviceDiscoveryListener deviceDiscoveryListener,
- ConnectionListener connectionListener}
name
is useful for host/device identification purposes especially if discovery
is enabled. If you specify a name, the name will be sent to communicating devices
to add as a user friendly name during discovery.
You can specify a multicastPort
if you want to use something else instead
of the default 5018. This is the port that the multicast group will be listening on.
You only need to set this if you plan to enable device discovery and advertisements.
ipVersion
is the version of IP to use for all addresses. Options are:
IPVersion.any, IPVersion.v4, and IPVersion.v6
The multicastGroupIP will use to 225.225.225.225 for IPVersion.v4 or IPVersion.any and will use FF02::FB for IPVersion.v6
If you enable discovery, you should provide a DeviceDiscoveryListener option to receive connection and disconnection events.
You should normally provide a ConnectionListener to receive events on connection and disconnection.
Implementation
Host({String name, int multicastPort, IPVersion ipVersion,
DeviceDiscoveryListener deviceDiscoveryListener, ConnectionListener connectionListener}){
_name = name?.replaceAll("|", "_") ?? "<Unknown Host>";
_multicastPort = multicastPort ?? DEFAULT_MULTICAST_PORT;
_ipVersion = ipVersion ?? IPVersion.any;
_multicastGroupIP = (_ipVersion == IPVersion.any || _ipVersion == IPVersion.v4 ?
DEFAULT_MULTICAST_GROUP_IPV4 : DEFAULT_MULTICAST_GROUP_IPV6);
_discoveryListener = deviceDiscoveryListener;
_connectionListener = connectionListener;
_discoveredDevices = Set();
}